apamphilon

Add class to body on scroll

//add class to body on scroll
$(window).on("scroll", function() {
    //from top is the amount of pixels to scroll from top before adding class
    var fromTop = $(window).scrollTop();
    $("body").toggleClass("down", (fromTop > 300));
});

credit

alternative

$(window).on("scroll", function() {
    //from top is the amount of pixels to scroll from top before adding class
    var fromTop = $(window).scrollTop();
    if (fromTop > 850) {
        $('.masthead').addClass('scroll');
    } else {
        $('.masthead').removeClass('scroll');
    }
});

Comments: