Skip to content

Instantly share code, notes, and snippets.

@MahbbRah
Last active March 31, 2021 09:54
Show Gist options
  • Save MahbbRah/347440d152f90d235e04119352fb9a61 to your computer and use it in GitHub Desktop.
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
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