Created
August 16, 2013 18:08
-
-
Save mateuszkocz/6252131 to your computer and use it in GitHub Desktop.
Timer in requestAnimationFrame. Source: https://developer.mozilla.org/en-US/docs/Web/API/window.requestAnimationFrame
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 start = null; | |
var d = document.getElementById("SomeElementYouWantToAnimate"); | |
function step(timestamp) { | |
var progress; | |
if (start === null) start = timestamp; | |
progress = timestamp - start; | |
d.style.left = Math.min(progress/10, 200) + "px"; | |
if (progress < 2000) { | |
requestAnimationFrame(step); | |
} | |
} | |
requestAnimationFrame(step); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment