Having discovered requestAnimationFrame
just a moment ago, I have dived into all the information I could find about it. To name just a few of the resources I came across in case there are others looking for more info about it:
- http://creativejs.com/resources/requestanimationframe/ - explains the basics about it.
- http://www.html5rocks.com/en/tutorials/speed/animations/ - explains how to use it.
Anyway, all of these resources tell me something about how requestAnimationFrame
works or how it could/should be used, but none of them tell me when it is right to use it.
- Should I use it for animations (repeated changes to the style of an element, much like CSS animations)?
- Should I use it when an automated event wants to change the css/classes of one or multiple elements?
- Should I use it when an automated event wants to change the text value of one or multiple elements? (e.g. updating the value of a clock once every second)
- Should I use it when an automated event wants to modify the DOM?
- Should I use it when an automated event needs values like .offsetTop, .offsetLeft and then wants to change styles such as top and left a few lines further?
- Should I use it when a user generated event causes any of the above changes?
TL;DR: When is it right to use requestAnimationFrame?