RequestAnimationFrame for smart animating
If you’ve never written code to animate inside the browser, you can stop reading :) What is requestAnimationFrame? In your animation work, you’ve used a timer loop to make changes every few milliseconds. Good for us: browser vendors have decided, “hey, why don’t we just give you an API for that, because we can probably optimize some things for you.” Why should I use it? The browser can optimize concurrent animations together into a single reflow and repaint cycle, leading to higher fidelity animation. OMG I can brag about having a site with battery-friendly animations? Yeah bro. How should I use this? Note: I am using ‘requestAnimFrame` here because since the spec is still in flux, I don’t want to make a straight polyfill, yet. 2012.01.07: The spec has gotten some fixes and settled down. A robust polyfill Opera engineer Erik Möller wrote about rAF and developed a polyfill that better handles browsers without native support. I have this polyfill available as a gist as well. Is it ready?
Related: Generative Art