Skip to content

Instantly share code, notes, and snippets.

@idettman
Created October 3, 2025 16:01
Show Gist options
  • Select an option

  • Save idettman/9f8aff4f37959767c5705dbbc1ad6dc4 to your computer and use it in GitHub Desktop.

Select an option

Save idettman/9f8aff4f37959767c5705dbbc1ad6dc4 to your computer and use it in GitHub Desktop.
Old request animation frame code
function animationLoop(render, element) {
const running, lastFrame = +new Date;
function loop(now) {
// stop the loop if render returned false
if (running !== false) {
requestAnimationFrame(loop, element);
const deltaT = now - lastFrame;
// do not render if deltaT is too high
if ( deltaT < 160 ) {
running = render(deltaT);
}
lastFrame = now;
}
}
loop(lastFrame);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment