Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save piersolenski/34a4c815f22fade2fad95acbd8fd7790 to your computer and use it in GitHub Desktop.
Save piersolenski/34a4c815f22fade2fad95acbd8fd7790 to your computer and use it in GitHub Desktop.
let starttime;
function moveit(timestamp, x, duration){
const runtime = timestamp - starttime;
let progress = Math.min((runtime / duration), 1);
console.log(x * progress);
if (runtime < duration) requestAnimationFrame(timestamp => moveit(timestamp, x, duration));
}
requestAnimationFrame(timestamp => {
starttime = timestamp;
moveit(timestamp, 400, 2000);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment