I'd like to do some fancy jQuery stuff when the user scrolls the page. But I have no idea how to tackle this problem, since there is only the scroll() method.
Any ideas?
I'd like to do some fancy jQuery stuff when the user scrolls the page. But I have no idea how to tackle this problem, since there is only the scroll() method.
Any ideas?
You can make the
scroll()
have a time-out that gets overwritten each times the user scrolls. That way, when he stops after a certain amount of milliseconds your script is run, but if he scrolls in the meantime the counter will start over again and the script will wait until he is done scrolling again.Update:
Because this question got some action again I figured I might as well update it with a jQuery extension that adds a
scrollEnd
eventHere is a simple example using setTimeout to fire a function when the user stops scrolling:
The timer is cleared while the scroll event is firing. Once scrolling stops, the refresh function is fired.
Or as a plugin:
To fire callback after 100ms of the last scroll event on a div (with namespace):
I use this for scroll and resize.