+ 11
What's the difference between setInterval() and requestAnimationFrame()
Which better to use?
2 Answers
+ 7
SetInterval() is less accurate than requestAnimationFrame() but more better supported by browsers ^^
SetInterval() wait for a delay before calling a function ( if you use it with a kind of recursivity by passing the actual function to it, the delay parameter doesn't include the time of code execution ), while requestAnimationFrame is designed for handle more accurate clocking functions by call them at a parameter frequency rather than a delay ( function call occurs every n times )