Skip to content

Instantly share code, notes, and snippets.

@rogeruiz
Created August 24, 2012 18:05
Show Gist options
  • Select an option

  • Save rogeruiz/3453652 to your computer and use it in GitHub Desktop.

Select an option

Save rogeruiz/3453652 to your computer and use it in GitHub Desktop.
A resize event timer which fires a resize event only after the user has stopped resizing the window.
# Keep track of how many times the event as been triggered versus how many times
# the timer has been fired.
resizeFiredTotal = 0
reizeFiredCounter = 0
# Bind a resize event to the window
$(window).on 'resize', (e) ->
# Increment the resize fired event by 1
resizeFiredTotal += 1
userResizing = () ->
# Check if the timer has fired more than the resize event itself.
if reizeFiredCounter >= resizeFiredTotal
console.log 'Do anything now that the user has stopped resizing', e if console.log?
else
reizeFiredCounter += 2
return
# Call the userResizing every 500 milliseconds.
setTimeout userResizing, 500
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment