天天看点

js实现头部悬停效果

只写js部分,其他的样式省略了,多请大家谅解。。。,有写的不好的请各路大神指正,感谢

<script>
	var nav =document.getElementById("nav");

	document.onscroll = function(){
		var h = document.body.scrollTop || document.documentElement.scrollTop;
		if(h>168){
			nav.style.top =0;
			nav.style.position = "fixed";
		}else{
			nav.style.position = "static";
		}
}
</script>