+ 6

How does requestAnimationFrame works?

So i am passing a callback function as well as argument to requestAnimationFrame, that argument has a value of 10 ,now if I log out that value in function it outputs 10 but when i pass a parameter to function it outputs time in milliseconds, Note: if you add a parameter d to function check,it will output time in ms https://code.sololearn.com/WTNCJbUz1M8H/?ref=app

7th Aug 2020, 10:35 AM
Abhay
Abhay - avatar
1 Réponse
+ 1
The requestAnimationFrame functions runs the callback function that is passed into it on every repaint of the browser's frame. It trys to optimize the speed to be as fast as the device it is being run on. The first parameter of the callback function also carries a value called a timestamp. This timestamp contains the total time (in milliseconds) that the callback function has been run by requestAnimationFrame(). The timestamp value is not constant, as it changes on every frame repaint.
9th Aug 2020, 10:18 PM
Samuel Adepoju
Samuel Adepoju - avatar