Makerere University

Enter a keyword or two into the search box above and click search..

Add/remove class with jquery based on vertical scroll

You are here

The Javascript

$(function() {
    //caches a jQuery object containing the header element
    var header = $(".clearHeader");
    $(window).scroll(function() {
        var scroll = $(window).scrollTop();

        if (scroll >= 500) {
            header.removeClass('clearHeader').addClass("darkHeader");
        } else {
            header.removeClass("darkHeader").addClass('clearHeader');
        }
    });
});

See it work on Fiddle

Category: