Created
August 24, 2017 15:07
-
-
Save bendc/5a4d5337895ac4d55210c06163c7359b to your computer and use it in GitHub Desktop.
rAF tutorial: basic time tracking
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 time = { | |
start: null, | |
total: 2000 | |
}; | |
const tick = now => { | |
if (!time.start) time.start = now; | |
time.elapsed = now - time.start; | |
if (time.elapsed < time.total) requestAnimationFrame(tick); | |
}; | |
requestAnimationFrame(tick); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment