Skip to content

Instantly share code, notes, and snippets.

@fitsum
Last active April 26, 2024 05:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fitsum/dd49b5d891df358d0b487b8411d7405f to your computer and use it in GitHub Desktop.
Save fitsum/dd49b5d891df358d0b487b8411d7405f to your computer and use it in GitHub Desktop.
request animation frame
var now, dt,
rate = 0.5,
last = performance.now();
function frame() {
now = performance.now();
dt = (now - last) / 1000; // duration in seconds
if(dt >= rate){
console.log("bing")
last = now;
}
requestAnimationFrame(frame);
}
requestAnimationFrame(frame);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment