Created
October 3, 2025 16:01
-
-
Save idettman/9f8aff4f37959767c5705dbbc1ad6dc4 to your computer and use it in GitHub Desktop.
Old request animation frame code
This file contains hidden or 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
| 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