If i want to bind an event on page scrolling i can use scroll();
.
But how to fire when scroll()
is ended up?
I would like to reproduce this:
$(window).scroll(function(){
//do somenthing
});
$(window).scrollSTOPPED(function(){ //--> when i'm scrolling then i stop to scrolling (so NOT when page scrollbar is at the end top or bottom :)
//do somenthing else
});
any ideas?
I prefer to be able to listen on a event. This is what I do:
The jquery plugin:
In this case, window will now trigger scrollStop event
Now I can listen on scrollStop
tiny jquery way
After 250 ms from the last scroll event, this will invoke the "scrollStopped" callback.
http://jsfiddle.net/wtRrV/256/
lodash (even smaller)
http://jsfiddle.net/hotw1o2j/
pure js (technically the smallest)
https://jsfiddle.net/kpsxdcv8/15/
strange fact
clearTimeout and clearInterval params don't have to be defined and can even be wrong types or even omitted.
http://jsfiddle.net/2w5zLwvx/
You can verify if
window.scrollY == 0
But this event will be fired at every scroll.
the event itself doesn't exist as scroll is a single event fired everytime the user scrolls by a certain increment.
What you can do however is emulate the event.
Credit to James Padolsey for this, lifted from his webpage:. Read it here to fully understand the code and how it is implemented.
http://james.padolsey.com/javascript/special-scroll-events-for-jquery/
Probably worth noting that there are several questions related to yours, so this may be a possible duplication. e.g. Javascript: do an action after user is done scrolling and Fire event after scrollling scrollbars or mousewheel with javascript