Created
August 24, 2012 18:05
-
-
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.
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
| # 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