JQuery绝对定位导航栏
作者:互联网
js代码:
$(function () { //获取.title的上偏移量 var startoffset = $(".title").offset().top; //滚动时执行 window.onscroll = function () { //获取当前滚动条的纵坐标位置||被卷走的高度 var stop = document.documentElement.scrollTop || document.body.scrollTop; if (stop >= startoffset) { $(".title").addClass("title_fixed"); } else { $(".title").removeClass("title_fixed"); } } })
css代码:
.title_fixed { position: fixed; top: 0; z-index: 100; }
End!
标签:JQuery,function,title,top,绝对,定位导航,startoffset,var,fixed 来源: https://www.cnblogs.com/gygg/p/12155025.html