Created
August 18, 2016 20:28
-
-
Save bendc/8e109434c5ef94310ecca9dfbc0f2e28 to your computer and use it in GitHub Desktop.
Better setInterval
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
const interval = (callback, delay) => { | |
const tick = now => { | |
if (now - start >= delay) { | |
start = now; | |
callback(); | |
} | |
requestAnimationFrame(tick); | |
}; | |
let start = performance.now(); | |
requestAnimationFrame(tick); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment