Skip to content

Instantly share code, notes, and snippets.

@DronRathore
Created February 8, 2015 18:18
Show Gist options
  • Save DronRathore/b56ee0b2b9ffcad20c59 to your computer and use it in GitHub Desktop.
Save DronRathore/b56ee0b2b9ffcad20c59 to your computer and use it in GitHub Desktop.
requestAnimationFrame
/*
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