我有一个.navigation
在包装纸的顶部。
我想添加一个.fixed
类,当窗口顶部到达.bottom
DIV 并在顶部时删除此类.bottom
位于窗口范围内(它是在添加和删除 .fixed 类之间切换)。
<div id="wrapper">
<div class="navigation">
<!-- There are some list elements here -->
</div>
<div class="bottom"></div>
</div>
这是我做的,但不是工作
bottom = $('.bottom');
$(window).scroll(function(){
if ($(this).scrollTop() > bottom){
$('.navigation').addClass('fixed');
}
else{
$('.navigation').removeClass('fixed');
}
});
var bottom = $('.bottom').offset().top;
应该可以做到这一点。
这会将视口顶部与窗口顶部的偏移量进行比较scrollTop()
而不是比较整个元素。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)