I love this post!
At its core,
requestAnimationFramedoesn’t do much: it’s basically just a method that executes a callback. In fact, there are very few differences between doing
doSomething(). So, what’s so special about it? I’m glad you asked! In short:
requestAnimationFrameschedules the callback call on the next repaint
requestAnimationFramepasses the callback the current time
There are a few other distinctions, but these are the main benefits. Now,
requestAnimationFramedoesn’t create an animation on its own, it’s the sequence of successive callbacks that will make things move on the screen.
My favorite part: since a large part of animating with
requestAnimationFrame consists of composing small mathematical expressions, you can apply all sorts of functional programming tricks to your code.
Learn all about it on Benjamin De Cock’s blog.