小编Far*_*yan的帖子

当窗口顶部到达特定元素时将类添加到 DIV 并在未到达时将其删除

.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)

html javascript css jquery

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

css ×1

html ×1

javascript ×1

jquery ×1