Affix is not working in Bootstrap 4 (alpha)

前端 未结 10 534
暖寄归人
暖寄归人 2020-12-02 21:30

According to Bootstrap 3 docs I have added following attributes to a navbar:

10条回答
  •  半阙折子戏
    2020-12-02 22:17

    To build on Anwar Hussain's answer. I found success with this:

    $(window).on('scroll', function (event) {
        var scrollValue = $(window).scrollTop();
        if (scrollValue > 120) {
            $('.navbar').addClass('affix');
        } else{
            $('.navbar').removeClass('affix');
        }
    });
    

    This will apply the class to the navbar when scrolling down, but will also remove the class when scrolling back up. Previously, when scrolling back up, the applied class would stay applied to the navbar.

提交回复
热议问题