Add class to the element on scroll

Marko Krstić
18 Feb 2022
$(window).scroll(function(){
    if ($(this).scrollTop() > 100) {
       $('.element').addClass('active');
    } else {
       $('.element').removeClass('active');
    }
});

Change element class or ID on lines 3 and 5 to trigger right elements and on line 2 100 is how many pixels to scroll until class is added.

Was this article helpful?

Tags

Categories

Never miss new post again

Subscribe and get list of new posts in your inbox

Click to Copy