Created
November 15, 2013 23:23
-
-
Save mrmurphy/7493416 to your computer and use it in GitHub Desktop.
Handy object to call any number of functions when a user has stopped scrolling. Uses jQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scrollNotifier = do -> | |
TIMEOUTINTERVAL = 50 | |
scrollTimer = null | |
returnable = {} | |
callbacks = [] | |
bound = false | |
mainCallback = -> | |
clearTimeout(scrollTimer) | |
scrollTimer = setTimeout( -> | |
for fn in callbacks | |
fn() | |
, TIMEOUTINTERVAL) | |
returnable.addCallback = (func) -> | |
if not bound | |
$(window).bind("scroll", mainCallback) | |
bound = true | |
callbacks.push func | |
return returnable |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment