+ 3

requestAnimationFrame() time interval

What's the simplest way to get the time interval between every two successive callbacks done by the requestAnimationFrame() function? Please help!

22nd Nov 2018, 10:04 AM
Moses Odhiambo
Moses Odhiambo - avatar
2 ответов
+ 3
requestAnimationFrame() method get a function callback as parameter, wich get a timestamp parameter with time (in ms) at wich your callback was called... save this value and substract it from next value: var callbacktime = 0; function mycallback(timestamp) { if (callbacktime) console.log(timestamp-callbacktime); callbacktime = timestamp; requestAnimationFrame(mycallback); } requestAnimationFrame(mycallback); https://developer.mozilla.org/en-US/docs/Web/API/Window/requestAnimationFrame
22nd Nov 2018, 4:56 PM
visph
visph - avatar
- 1
how do I post images on the play ground
1st Dec 2018, 8:31 PM
Ifenna Monanu
Ifenna Monanu - avatar