Observe an element when a new class

2

It would be these fixed frontend bars, the problem is that I can not find how a class is inserted to by things in it.

Example:

<div class="main-menu">conteudo</div>

After rolling the screen a bit, the class is inserted:

<div class="main-menu isStuck">conteudo</div>

I need to be observing when and when to remove this class for some "clones" within it.

    
asked by anonymous 11.11.2017 / 19:52

1 answer

1

Use .on with scroll to observe, when scrolling the screen, whether or not the element has class :

$(window).on('scroll', function(){
   if($('.main-menu').hasClass('isStuck')){
     console.log("tem a classe");
   }else{
     console.log("não tem a classe");
   }
});
    
11.11.2017 / 20:08