Ilyas Dattoo Ilyas Dattoo - 6 months ago 84
Javascript Question

Bootstrap 4 Affix is not working

According to bootstrap 3 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 any one tell me how to solve this problem, Bootstrap.js and jQuery.js is working. Thanks in advance!

Answer

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 || 70) {
        // add class to navbar
    }
});