Skip to content

Instantly share code, notes, and snippets.

@luigimannoni
Created October 29, 2015 14:31
Show Gist options
  • Select an option

  • Save luigimannoni/109d2fe2bfb966cfff2e to your computer and use it in GitHub Desktop.

Select an option

Save luigimannoni/109d2fe2bfb966cfff2e to your computer and use it in GitHub Desktop.
RequestAnimationFrame Polyfill for IE9-
// RAF Polyfill
var lastTime = 0,
vendors = ['ms', 'moz', 'webkit', 'o'],
x,
length,
currTime,
timeToCall;
for(x = 0, length = vendors.length; x < length && !window.requestAnimationFrame; ++x) {
window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
window.cancelAnimationFrame =
window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelRequestAnimationFrame'];
}
if (!window.requestAnimationFrame)
window.requestAnimationFrame = function(callback, element) {
currTime = new Date().getTime();
timeToCall = Math.max(0, 16 - (currTime - lastTime));
lastTime = currTime + timeToCall;
return window.setTimeout(function() { callback(currTime + timeToCall); },
timeToCall);
};
if (!window.cancelAnimationFrame)
window.cancelAnimationFrame = function(id) {
clearTimeout(id);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment