jQuery – How can scroll UP/DOWN be distinguished??

13 years ago, October 28, 2011
Reading time: 1 mins

How can UP/DOWN scroll be distinguished in jQuery?

The easiest and best way for me to tell was…

var tempScrollTop, currentScrollTop = 0;
currentScrollTop = $("#div").scrollTop();
if (tempScrollTop < currentScrollTop )
//scrolling down
else if (tempScrollTop > currentScrollTop )
//scrolling up
tempScrollTop = currentScrollTop;

This works with mousewheel, up/down arrows, and slider.

If you need to detect only mousewheel scroll you can do following:


if(a < 0){
// scrolling down
//scrolling up


If you want to use mouse scroll to scroll horizontally on any html element instead of scrolling vertical please go through the following post

scroll-horizontally-on-mouse-wheel-scroll — Example:- horizontal-scroller-showcase

latency of the NTCs ADSL gateway from my home so high often request times out.
Alter the JS paths included in theme.info through template.php
© 2024 Anil Maharjan