Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
requestAnimationFrame polyfill
/** @type {function((Function|string)):number} */
var requestAnimationFrame = window.requestAnimationFrame || ( function() {
/** @type {Array.<Function>} */
var queue = [];
/** @type {number} */
var last = Date.now() - 100 / 6;
( function frame() {
var n = Date.now();
var l = last;
var q = queue.splice( 0 );
while ( q.length ) {
q.shift()( n );
}
last = n;
setTimeout( frame, 100 / 3 - n + l );
}() );
return queue.push.bind( queue );
}() );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.