Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@blooddy
Forked from paulirish/rAF.js
Last active January 4, 2017 18:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blooddy/3987045 to your computer and use it in GitHub Desktop.
Save blooddy/3987045 to your computer and use it in GitHub Desktop.
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