Capturing actions: Scroll Down and Scroll Up

5

Is there any way in jQuery to capture the events of "ScrollDown" and "ScrollUp"?

I tried this way:

var lastScrollTop = 0;
$(window).scroll(function(event){
   var st = $(this).scrollTop();
   if (st > lastScrollTop){
      // downscroll code
   } else {
      // upscroll code
   }
   lastScrollTop = st;
}); 

But it does not capture the UP and DOWN functions, but the scroll function!

And I wanted that as soon as the mouse roll was fired the function would be executed.

Is this possible?

    
asked by anonymous 13.07.2014 / 21:36

1 answer

5

The code that you put in does what you want. There is no other property of the event that is a direction indicator, it has to be measured.

If you'd like to know specifically how to measure the direction of the mouse wheel, it's possible to take out the properties of evento (take a look here: How to know the direction of scrolling the mouse wheel ).

But the scroll is more comprehensive is triggered in other ways and not just the mouse wheel.

Take a look here to see your code working: jsfiddle.net/ayxqg/1/

    
14.07.2014 / 01:28