JAVASCRIPT - HOW TO Detect Scrolling Stopped OR Directon of Scroll - Javascript Source Code

JAVASCRIPT - HOW TO Detect if your Website Visitor has Stopped Scrolling the Page and if they have NOT Stopped Scrolling, which Direction they are Scrolling - Scrolling Up or Scrolling Down

Home Short:

To detect when a website visitor has stopped vertical up/down scrolling and the direction the are scrolling, up or down, if they have not stopped scrolling and are currently scrolling, involves setting a timer that stores the window.pageYoffset in a global variable and then comparing that value to the current window.pageYoffset.

If the visitor stopped scrolling there will be no difference between the global variable and the value of window.pageYoffset and teh return of the function will be 0.

If the website visitor is currently scrolling then the function will return ...

  1. A positive number if the website visitor is scrolling down.
  2. A negative number if the website visitor is scrolling up.

Feel free to right click this page to view the source to see how to use this Javascript code to detect if scrolling has stopped or what direction the website visitor is scrolling.

S
H
A
R
E