Re:Learning from Twitter
by dionidium on Thursday January 20, 2011 @05:34PM
(#2125596)
I use a generic version of the waiting-for-pause trick:
Use it like this:
Edit: Oops! The version in the article runs some code if any scroll event occurred since it last fired, but this one doesn't execute the callback until the user stops scrolling for some amount of time. Anyway, maybe it's still useful for some folks.
[ Parent
| on HN ]
For anyone that's interested, two related techniques are called "throttling" and "debouncing".
Re:Learning from Twitter
by ryankirkman on Friday January 21, 2011 @04:59AM
(#2126976)
Both of which are available in the awesome Underscore.js library: http://documentcloud.github.com/underscore/
I've used that idiom too. It's a great trick. One potential issue is that if you continuously trigger the scroll/resize event, your callback will go an extended time without firing. That's usually only a problem if you're using it to adjust UI elements on scroll/resize, in which case you'd want to add a timer to force the callback if the delay has been too long despite the event still firing often.