Search code examples
javascriptcsstwitter-bootstrapaffixbootstrap-4

Affix is not working in Bootstrap 4 (alpha)


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

<nav class="navbar no-margin-bottom" data-spy="affix" data-offset-top="90" >
...
</nav>

After scrolling down the page Bootstrap 4 is not adding class to navbar which is affix. Can anyone tell me how to solve this problem? Bootstrap.js and jQuery.js are working.


Solution

  • Although the affix is removed from Bootstrap in version 4. However, you can achieve your goal through this jQuery Code:

    $(window).on('scroll', function(event) {
        var scrollValue = $(window).scrollTop();
        if (scrollValue == settings.scrollTopPx || scrollValue > 70) {
             $('.navbar').addClass('fixed-top');
        } 
    });