`requestAnimationFrame` should call itself
This style of animation is useful when you're making small changes via
javascript. When you pass requestAnimationFrame
a callback, the callback is
called before a browser repaint, or about 60 times a second. To make sure that
you're getting 60 callbacks a second, you must call requestAnimationFrame
from within your callback.
function animate() {
makeSomeSmallChangeToHtmlOrCss();
requestAnimationFrame(animate);
}
This is a recursive function, so without an exit condition, it will recurse infinitely.
H/T Brian Dunn
Tweet