jQuery: Detect 'classes' changes on an element while scrolling down the page

时间:2016-04-04 18:53:10

标签: jquery

I am looking for a way to detect changes on the classes of a header element, that are been applied during scrolling down from another script.

So, when a specific class is applied on the header, I want to run my function on another element.

So something like (if that makes any sense):

$('html').scroll(function(){ // So while scrolling down the page
    // if header gets the class
    if (('#header').hasClass('header-scrolled')) {
        alert('ops'); 
    }
})

I am not sure on how to approach this. Any guidance would be appreciated.

1 个答案:

答案 0 :(得分:1)

You can listen to scroll event on window element:

$(window).on('scroll', function() {
   //Check classes
});