I've been trying to research how to use requestAnimationFrame and I've ended up very confused.
According to Mozilla, if you have an animation function called 'step' that you call with requestAnimationFrame(step)
, step
accepts an argument that is a number of milliseconds, a DOMHighResTimeStamp argument.
And yet every single example I've seen online of how to use requestAnimationFrame does not use this argument. Some examples insist that you can assume the step
function will run 60 times a second, and so they don't use any time
concepts at all. Others get their own "number of milliseconds" separate from the argument, by using new Date();
- I suppose it's easy enough to modify these examples to use the argument instead.
Is it ok to assume the function will run 60 times a second? Seems...unwise to me. Mozilla says "The number of callbacks is usually 60 times per second, but will generally match the display refresh rate in most web browsers as per W3C recommendation", which doesn't make me comfortable with that assumption. Is there a reason why people are using their own new Date()
way of getting milliseconds rather than using the argument?