+ 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!
2 odpowiedzi
+ 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
- 1
how do I post images on the play ground