summaryrefslogtreecommitdiffstats
path: root/src/polyfill.js
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2015-02-28 20:56:40 +0100
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2015-02-28 20:56:40 +0100
commit2fc54cb89bef303efa9be3dfcd26ff10921deb04 (patch)
tree50a3aa53cfe91b4055fdedfbca6b5195fbf851c6 /src/polyfill.js
parent02e88d9e4186bff0570b7cd05dd19ea9c6ed6dc8 (diff)
downloadsvg.js-2fc54cb89bef303efa9be3dfcd26ff10921deb04.tar.gz
svg.js-2fc54cb89bef303efa9be3dfcd26ff10921deb04.zip
Added `cancelAnimationFrame`-Polyfill, fixes #316
Diffstat (limited to 'src/polyfill.js')
-rw-r--r--src/polyfill.js30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/polyfill.js b/src/polyfill.js
index 3a3c25c..a913337 100644
--- a/src/polyfill.js
+++ b/src/polyfill.js
@@ -11,4 +11,32 @@ if (typeof CustomEvent !== 'function') {
CustomEvent.prototype = window.Event.prototype
window.CustomEvent = CustomEvent
-} \ No newline at end of file
+}
+
+// requestAnimationFrame / cancelAnimationFrame Polyfill with fallback based on Paul Irish
+(function(w) {
+ var lastTime = 0
+ var vendors = ['moz', 'webkit']
+
+ for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
+ w.requestAnimationFrame = w[vendors[x] + 'RequestAnimationFrame']
+ w.cancelAnimationFrame = w[vendors[x] + 'CancelAnimationFrame'] ||
+ w[vendors[x] + 'CancelRequestAnimationFrame']
+ }
+
+ w.requestAnimationFrame = w.requestAnimationFrame ||
+ function(callback) {
+ var currTime = new Date().getTime()
+ var timeToCall = Math.max(0, 16 - (currTime - lastTime))
+
+ var id = w.setTimeout(function() {
+ callback(currTime + timeToCall)
+ }, timeToCall)
+
+ lastTime = currTime + timeToCall
+ return id
+ }
+
+ w.cancelAnimationFrame = w.cancelAnimationFrame || w.clearTimeout;
+
+}(window)) \ No newline at end of file