Created
February 8, 2015 18:18
-
-
Save DronRathore/b56ee0b2b9ffcad20c59 to your computer and use it in GitHub Desktop.
requestAnimationFrame
This file contains 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
/* | |
Sample from MDN | |
*/ | |
var start = null; | |
var element = document.getElementById("SomeElementYouWantToAnimate"); | |
function step(timestamp) { | |
if (!start) start = timestamp; | |
var progress = timestamp - start; | |
element.style.left = Math.min(progress/10, 200) + "px"; | |
if (progress < 2000) { | |
window.requestAnimationFrame(step); | |
} | |
} | |
window.requestAnimationFrame(step); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment