通过js获取视口高度,当超过高度时改变position的值为fixed,html在相应标签加入id= "float"
/**
* Created by 刘吴江 on 2018/5/1.
*/
window.onload=
???function(){
???????var oDiv = document.getElementById("float"),
???????????H = 0,
???????????Y = oDiv
???????while (Y) {H += Y.offsetTop; Y = Y.offsetParent}
???????window.onscroll = function()
???????{
???????????var s = document.body.scrollTop || document.documentElement.scrollTop
???????????if(s>H) {
???????????????oDiv.style = "position:fixed;top:0;"
???????????} else {
???????????????oDiv.style = ""
???????????}
???????}
???}
js控制导航滚动
原文地址:https://www.cnblogs.com/liuwujiang/p/8978019.html