mardi 21 avril 2015

Navbar add class after div scrolls with jQuery

I have problems adding a class to the navigation after scrolling to get a fixed class. My website has a video in the background and only the <div> with the .wrap class can scroll all the content. When scrolling I would like the navigation to be fixed on top.

This is my Javascript code:

$(document).ready(function() {
    var navpos = $('.navbar').offset();
    console.log(navpos.top);
    $(window).bind('scroll', function() {
        if ($(window).scrollTop() > navpos.top) {
            $('.navbar').fadeIn(500).addClass('fixed-top');
        }else {
           $('.navbar').removeClass('fixed-top');
        }
    });
});

But the problem is that the body is in fixed position and only the content wrap is actually scrolling. How do I fix this?

Aucun commentaire:

Enregistrer un commentaire