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.
source
share