Today I Learned

hashrocket A Hashrocket project

`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

See More #javascript TILs
Looking for help? At Hashrocket, our JavaScript experts launch scalable, performant apps on the Web, Android and iOS. Contact us and find out how we can help you.