Created
April 30, 2013 02:05
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for working on this : ) What is the browser support?