If you’re curious about the new
requestAnimationFrame API, here’s a demo along with a code walk-through:
requestAnimationFrame API is a replacement for
setInterval in the context of HTML animations. It has two primary advantages over timer functions:
- It is synchronized with the browser’s repaint loop which allows for more highly optimized animations.
- Since it’s specifically designed and intended to be used for animation rather than being a general purpose timer, the browser knows that it’s safe to throttle it back when the tab isn’t active. Throttling back animations means freeing up CPU cycles, and reducing unnecessary battery drain on mobile devices.
If you want to see this animation in action (and/or check out the code), it’s available here (Hint: if it’s running slowly, try making your browser window smaller). Thanks to Chris Georgenes for the “rocker girl” animation. And finally, here are the resources I used to learn about