我.navigation在包装纸的顶部有一个。我想给它添加一个.fixed类,当窗口顶部到达.bottomDIV时,当顶部在窗口.bottom的范围内时删除这个类(这是在添加和删除 .fixed 类之间切换)。

<div id="wrapper">
<div class="navigation">
<!-- There are some list elements here -->
</div>
<div class="bottom"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
这是我做的,但不起作用
bottom = $('.bottom');
$(window).scroll(function(){
if ($(this).scrollTop() > bottom){
$('.navigation').addClass('fixed');
}
else{
$('.navigation').removeClass('fixed');
}
});
Run Code Online (Sandbox Code Playgroud)