Skip to content

Instantly share code, notes, and snippets.

@yckart
Created April 30, 2013 02:05
Show Gist options
  • Select an option

  • Save yckart/5486197 to your computer and use it in GitHub Desktop.

Select an option

Save yckart/5486197 to your computer and use it in GitHub Desktop.
requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel refactored by Yannick Albert
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
// refactored by Yannick Albert
// MIT license
(function(window) {
var equestAnimationFrame = 'equestAnimationFrame',
requestAnimationFrame = 'r' + equestAnimationFrame,
ancelAnimationFrame = 'ancelAnimationFrame',
cancelAnimationFrame = 'c' + ancelAnimationFrame,
expectedTime = 0,
vendors = ['moz', 'ms', 'o', 'webkit'],
vendor;
while(!window[requestAnimationFrame] && (vendor = vendors.pop())) {
window[requestAnimationFrame] = window[vendor + 'R' + equestAnimationFrame];
window[cancelAnimationFrame] = window[vendor + 'C' + ancelAnimationFrame] || window[vendor + 'CancelR' + equestAnimationFrame];
}
if(!window[requestAnimationFrame]) {
window[requestAnimationFrame] = function(callback) {
var currentTime = new Date().getTime(),
adjustedDelay = 16 - (currentTime - expectedTime),
delay = adjustedDelay > 0 ? adjustedDelay : 0;
expectedTime = currentTime + delay;
return setTimeout(function() {
callback(expectedTime);
}, delay);
};
window[cancelAnimationFrame] = clearTimeout;
}
}(this));
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
// refactored by Yannick Albert
// MIT license
(function(c){var b="equestAnimationFrame",f="r"+b,a="ancelAnimationFrame",e="c"+a,d=0,h=["moz","ms","o","webkit"],g;while(!c[f]&&(g=h.pop())){c[f]=c[g+"R"+b];c[e]=c[g+"C"+a]||c[g+"CancelR"+b]}if(!c[f]){c[f]=function(l){var k=new Date().getTime(),i=16-(k-d),j=i>0?i:0;d=k+j;return setTimeout(function(){l(d)},j)};c[e]=clearTimeout}}(this));
@wamoyo
Copy link
Copy Markdown

wamoyo commented May 15, 2015

Thanks for working on this : ) What is the browser support?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment