How to detect scrolling with jQuery

Posted on under English, Tutorials

Beware! This post is more than 3 years old, it may be outdated or incorrect! Please check elsewhere for accurate information!

I often find tutorials on this topic that are either false or assume that you want to detect the whole page scrolling. Usually that's not the case and you only want to detect a div's scroll position.

Create a div with overflow-x: auto; and a fixed height (not height: auto;). Now put this code in your $(document).ready() segment and it should work.

Note: Every time you update the div's contents you must run this code again, it doesn't work with $(element).on('scroll').

This post was last updated on July 26th, 2014.