When implemented JS scroll bar to scroll to the specified position, the anchor effect realized replacing the label style

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/PrisonersDilemma/article/details/90168759

Effect Description:
When a page scrolling volume to the highly visible,
increase class name 'top-fixed' by tags control the style header.

	$(window).on('scroll',()=>{
		let $fixedheader = $('header'); // fixed容器
		// console.log(fixedheader);
		var wintop=$(window).scrollTop(); // 已滚动卷去的高度
		// console.log(wintop);
		let winHeight = $(window).height(); // 可视窗口的高度
		// console.log(winHeight);
		// 卷去一个可视窗口高度后执行
		if (wintop - winHeight > 0) {
			// fixedheader.hide();
			$fixedheader.addClass("top-fixed");
		} else {
			// fixedheader.show();
			$fixedheader.removeClass("top-fixed");
		}
	})
/* 固定顶部 */
		header{
			height:114px;
		}
		.top-fixed{
			position:fixed;
			animation:mymove .5s forwards; 
			z-index:10;
		}
		@keyframes mymove{
			from {
				top:-114px;
			}
			to {
				top:0px;
			}
		}

Guess you like

Origin blog.csdn.net/PrisonersDilemma/article/details/90168759