Skip to content

Instantly share code, notes, and snippets.

@mrmurphy
Created November 15, 2013 23:23
Show Gist options
  • Save mrmurphy/7493416 to your computer and use it in GitHub Desktop.
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
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