Ilyas Dattoo Ilyas Dattoo - 2 years ago 488
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" >

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 Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download