This script only controls the page loading, How can I make this control during all navigation?

3

This script checks for the existence of class hide-bar in id header when loading the page when the class is not yet added to it. I need to find a solution so that as soon as the class is added to the id that is exactly when there is a page scroll, the script runs.

jQuery(function($){

    $( "#header", function() {
        //////////////////////////////////////////////
        if ( $("#header").hasClass("hide-bar") ){
             alert("A classe está adicionada.");
        }

    }); 

});
    
asked by anonymous 13.12.2014 / 16:17

1 answer

3

You need to "hear" the scroll / scroll event.

You can do this:

 $(window).on('scroll', function() {
    if ($("#header").hasClass("hide-bar")){
         alert("A classe está adicionada.");
    }
});

This way when the event happens it will call this code and do the verification.

If you need to know the position of the scroll, you can use $(window).scrollTop(); which will give you the scroll value at the moment.

    
13.12.2014 / 16:23