From 236fd1d9f2009083fbbfce7190c27fbf1d7c88b8 Mon Sep 17 00:00:00 2001 From: yo mama Date: Fri, 7 Aug 2015 18:33:30 -0700 Subject: getting ready --- frontend/imlandscape/js/RequestAnimationFrame.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 frontend/imlandscape/js/RequestAnimationFrame.js (limited to 'frontend/imlandscape/js/RequestAnimationFrame.js') 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); + }; +}()); -- cgit v1.2.3-70-g09d2