向下滚动导航栏固定顶部容器流体时引导导航栏容器

罗素

当它向下滚动固定在顶部的导航栏和同时容器流体时,我想向你们寻求一些关于引导导航栏容器的帮助

我的意思是说

我还为您提供了 codepen 链接,以便您玩弄Codepen div

扎基

所以,

如果我理解您的问题,您希望在用户开始滚动后将导航栏附加到顶部。好吧,这是我对此的实现......我使用了这个答案https://stackoverflow.com/a/21301875并针对这种情况修改了它并记录了代码。

代码笔

/**
 * Scroll management
 */
$(document).ready(function () {

    // Define the menu we are working with
    var menu = $('.navbar.navbar-default.navbar-inverse');

    // Get the menus current offset
    var origOffsetY = menu.offset().top;

    /**
     * scroll
     * Perform our menu mod
     */
    function scroll() {

        // Check the menus offset. 
        if ($(window).scrollTop() >= origOffsetY) {

            //If it is indeed beyond the offset, affix it to the top.
            $(menu).addClass('navbar-fixed-top');

        } else {

            // Otherwise, un affix it.
            $(menu).removeClass('navbar-fixed-top');

        }
    }

    // Anytime the document is scrolled act on it
    document.onscroll = scroll;

});

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章