Last active
April 26, 2024 05:26
-
-
Save fitsum/dd49b5d891df358d0b487b8411d7405f to your computer and use it in GitHub Desktop.
request animation frame
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
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