summaryrefslogtreecommitdiff
path: root/frontend/imlandscape/js/RequestAnimationFrame.js
diff options
context:
space:
mode:
authoryo mama <pepper@scannerjammer.com>2015-08-07 18:33:30 -0700
committeryo mama <pepper@scannerjammer.com>2015-08-07 18:33:30 -0700
commit236fd1d9f2009083fbbfce7190c27fbf1d7c88b8 (patch)
tree6077ff15b4b770b4b292aaa14d9cbfff1ba82fae /frontend/imlandscape/js/RequestAnimationFrame.js
parentc89619f1b1f908d0f330c468866cea669ce8bf6c (diff)
getting ready
Diffstat (limited to 'frontend/imlandscape/js/RequestAnimationFrame.js')
-rw-r--r--frontend/imlandscape/js/RequestAnimationFrame.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/frontend/imlandscape/js/RequestAnimationFrame.js b/frontend/imlandscape/js/RequestAnimationFrame.js
new file mode 100644
index 0000000..b1940ae
--- /dev/null
+++ b/frontend/imlandscape/js/RequestAnimationFrame.js
@@ -0,0 +1,24 @@
+(function() {
+ var lastTime = 0;
+ var vendors = ['webkit', 'moz'];
+ 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]+'CancelRequestAnimationFrame'];
+ }
+
+ 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(currTime + timeToCall); },
+ timeToCall);
+ lastTime = currTime + timeToCall;
+ return id;
+ };
+
+ if (!window.cancelAnimationFrame)
+ window.cancelAnimationFrame = function(id) {
+ clearTimeout(id);
+ };
+}());