Created
April 24, 2018 17:34
-
-
Save corycook/670858df7e90e597ea384832395e3b41 to your computer and use it in GitHub Desktop.
A simple throttle function.
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
| function throttle(fn) { | |
| let waiting = false; | |
| return function() { | |
| if (!waiting) { | |
| waiting = true; | |
| requestAnimationFrame(() => { | |
| waiting = false; | |
| fn.apply(this, arguments); | |
| }); | |
| } | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment