public
Last active

  • Download Gist
paulirish revised this gist . 1 changed file with 3 additions and 2 deletions. View gist @ 682e5c8
rAF.js
5 
... 1 2 3 4 5       6 7 8 ... 1 2 3     4 5 6 7 8 9
@@ -1,8 +1,9 @@
// 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
+// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
+
+// MIT license
(function() {
var lastTime = 0;
paulirish revised this gist . 1 changed file with 1 addition and 1 deletion. View gist @ 19b7f94
rAF.js
2 
... 10 11 12 13   14 15 16 ... 10 11 12   13 14 15 16
@@ -10,7 +10,7 @@
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame']
- || window[vendors[x]+'RequestCancelAnimationFrame'];
+ || window[vendors[x]+'CancelRequestAnimationFrame'];
}
if (!window.requestAnimationFrame)
paulirish renamed this gist . 1 changed file with 0 additions and 0 deletions. View gist @ 4035c27
gistfile1.js → rAF.js
File renamed without changes
paulirish revised this gist . 1 changed file with 1 addition and 1 deletion. View gist @ 893d292
gistfile1.js
2 
... 17 18 19 20   21 22 23 ... 17 18 19   20 21 22 23
@@ -17,7 +17,7 @@
window.requestAnimationFrame = function(callback, element) {
var currTime = new Date().getTime();
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
- var id = window.setTimeout(function() { callback(timeToCall); },
+ var id = window.setTimeout(function() { callback(currTime + timeToCall); },
timeToCall);
lastTime = currTime + timeToCall;
return id;
paulirish revised this gist . 1 changed file with 5 additions and 2 deletions. View gist @ 9c8ccfa
gistfile1.js
7 
...   1 2     3 4 5 ... 1 2   3 4 5 6 7
@@ -1,5 +1,7 @@
+// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
-// authored by Erik Möller
+
+// requestAnimationFrame polyfill by Erik Möller
// fixes from Paul Irish and Tino Zijdel
(function() {
... 7 8 9 10     11 12 13 ... 9 10 11   12 13 14 15 16
@@ -7,7 +9,8 @@
var vendors = ['ms', 'moz', 'webkit', 'o'];
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
- window.cancelAnimationFrame = window[vendors[x]+'RequestCancelAnimationFrame'];
+ window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame']
+ || window[vendors[x]+'RequestCancelAnimationFrame'];
}
if (!window.requestAnimationFrame)
paulirish created this gist . View gist @ 79945b2
gistfile1.js
27 
...                                                         ... 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27  
@@ -0,0 +1,27 @@
+// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
+// authored by Erik Möller
+// fixes from Paul Irish and Tino Zijdel
+
+(function() {
+ var lastTime = 0;
+ var vendors = ['ms', 'moz', 'webkit', 'o'];
+ for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
+ window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
+ window.cancelAnimationFrame = window[vendors[x]+'RequestCancelAnimationFrame'];
+ }
+
+ if (!window.requestAnimationFrame)
+ window.requestAnimationFrame = function(callback, element) {
+ var currTime = new Date().getTime();
+ var timeToCall = Math.max(0, 16 - (currTime - lastTime));
+ var id = window.setTimeout(function() { callback(timeToCall); },
+ timeToCall);
+ lastTime = currTime + timeToCall;
+ return id;
+ };
+
+ if (!window.cancelAnimationFrame)
+ window.cancelAnimationFrame = function(id) {
+ clearTimeout(id);
+ };
+}());
\ No newline at end of file
Something went wrong with that request. Please try again.