RequestAnimationFrame: what is a timestamp?

I always thought that the timestamp used by requestAnimationFrame is the same as the usual timestamp in JavaScript, i.e. the number of milliseconds since January 1, 1970. Today I took timestamps to check and found that the RAF timestamp was probably measured since the start of the page load. What are accurately measured timestamps?

Security Code:

<p id="output"></p>

var i = 0;
var start = null;
var times = [];
var dur = 5000;

function step(timestamp) {
 if (start===null) start = timestamp;
 times[i++] = timestamp;
 if (timestamp-start<=dur) {
  requestAnimationFrame(step);
 } else {
  document.getElementById('output').innerHTML = times.join('<br>');
 }
}

requestAnimationFrame(step);

gives the following results:

158.52126457412882
183.12243595205535
199.52116819316421
...

in all browsers that support RAF.

+4
source share
2 answers

Finally, I found the answer in an article by Paul Irrish and the high-resolution time specification:

requestAnimationFrame API: now accurate to milliseconds

A high resolution

rAF " ", "navigationStart PerformanceTiming".

+1

a DOMHighResTimeStamp ( window.performance.now()).

:

, requestAnimationFrame .

:

DOMTimeStamp , DOMHighResTimeStamp .

: rAF .

:

+7

Source: https://habr.com/ru/post/1523399/


All Articles