Last active
March 31, 2021 09:54
-
-
Save MahbbRah/347440d152f90d235e04119352fb9a61 to your computer and use it in GitHub Desktop.
Pattern for using requestAnimationFrame instead setInterval or setTimeout because it's much efficient and faster
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
let request | |
const performAnimation = () => { | |
request = requestAnimationFrame(performAnimation) | |
//You can do whatever you want continously or conditional based on your needs, have fun! | |
//Here your code goes for using as setTimeout simply call cancelAnimationFrame(request) or to use as setInterval don't use the cancelAnimation | |
} | |
requestAnimationFrame(performAnimation) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment