diff options
author | gschutz <guilherme@gschutz.com> | 2015-05-18 15:51:40 -0300 |
---|---|---|
committer | gschutz <guilherme@gschutz.com> | 2015-05-18 15:55:16 -0300 |
commit | 76a236a54c1e9b8457d9b13820fd6fa678df95dd (patch) | |
tree | ae4b22f4430661df83bd29a27098f28a9fe65caf /src/polyfill.js | |
parent | 54b3f3f1aab6204624189b5ef04b7ea30125a455 (diff) | |
parent | 0d1e85f6e3953461808c70366528c2ac3ce7903b (diff) | |
download | svg.js-76a236a54c1e9b8457d9b13820fd6fa678df95dd.tar.gz svg.js-76a236a54c1e9b8457d9b13820fd6fa678df95dd.zip |
Merge remote-tracking branch 'upstream/master' generate the build
Diffstat (limited to 'src/polyfill.js')
-rw-r--r-- | src/polyfill.js | 30 |
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 |