How to make Bootstrap 3 Fixed Navbar Collapse on Scroll using jQuery

Check out my other posts and tutorials on Web Development!

Use the following snippet to collapse Bootstrap 3’s fixed navbar when scrolling.

// collapse the navbar on scroll
$(window).scroll(function() {
    if ($(".navbar").offset().top > 50) {
        $(".navbar-fixed-top").addClass("top-nav-collapse");
    } else {
        $(".navbar-fixed-top").removeClass("top-nav-collapse");
    }
});

Leave a Reply

Contact Us

Subscribe

Subscribe to our blog to receive latest news and tutorials on Web Design, Development, SEO, and more!