0

Is there any way in JQuery to capture events scrolldown / 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 function of UP and DOWN, but the scroll whatsoever!

And I wanted so the scrolling mouse were activated the function were executed!

Is this possible?

Samir Braga
  • 101
  • 1
  • 2
  • This is a duplicate of -> http://stackoverflow.com/questions/4326845/how-can-i-determine-the-direction-of-a-jquery-scroll-event, but as you've copied the code directly from that question, and can't get it to work, you probably have other issues. – adeneo Jul 13 '14 at 20:17
  • Are you sure jQuery is included properly, and that the scrollbar really belongs to the window etc. – adeneo Jul 13 '14 at 20:18
  • It does seem to work perfectly in a [**Fiddle**](http://jsfiddle.net/adeneo/cANVC/), as expected. – adeneo Jul 13 '14 at 20:19
  • Actually what I want to do is even a page that when the user is scrooling the page vertically, the scrolling happens horizontally – Samir Braga Jul 13 '14 at 20:29
  • If my comments are with syntax errors, please do not find it bad, and the reason I am Brazilian and I am not fluent in English to some things are being translated in google translator – Samir Braga Jul 13 '14 at 20:42
  • Then you'd change it to `$(this).scrollLeft()` etc – adeneo Jul 13 '14 at 20:53
  • I already tried that! But it did not work well. – Samir Braga Jul 13 '14 at 20:57

0 Answers0