-
-
Save AmesianX/fa4bceea1748da01708cd2e21ee4dadb 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