Created
October 23, 2015 22:25
-
-
Save xfsnowind/c19d58f6fb131d28778e to your computer and use it in GitHub Desktop.
apply debounce to resize event on blog "Introducing Javascript method debounce" on 2014/05/12
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
| var timeout; | |
| $(window).resize(function () { | |
| function delayed () { | |
| //the operation needed | |
| timeout = null; | |
| } | |
| if (timeout) { | |
| clearTimeout(timeout); | |
| } | |
| timeout = setTimeout(delayed, 500); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment