In jquery, the .scroll()
listener...
is a shortcut for .on( "scroll", handler )
...
The scroll event is sent to an element when the user scrolls to a different place in the element. It applies to window objects, but also to scrollable frames and elements with the overflow CSS property set to scroll (or auto when the element's explicit height or width is less than the height or width of its contents).
In other words, it will fire for a div with a scroll bar when the user scrolls it.
However, be warned
...high frequency events such as mousemove
or scroll can
fire dozens of times per second, and in those cases it becomes more important to use events judiciously.
You mention scrolling down, which will require computation and memory between the event handles. This puts you in danger of harming performance with a naive scroll handler.
I would suggest the following approach:
- Don't do the work in the
.scroll
handler itself, just use it as a catalyst for starting the work.
- Have the scroll handler remove itself, so it doesn't keep firing all the time, once you've determined the event is a downward scroll.
- Instead, set a timeout to re-check whether or not the user is still scrolling down.
- If they've stopped scrolling, remove your css from the class in question and re-add the scroll handler to the DOM element in question, so if they scroll again, you're good to go.