diff options
author | wout <wout@impinc.co.uk> | 2014-01-28 15:43:43 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2014-01-28 15:43:43 +0100 |
commit | e04f8d1b3595c65e245465606e3987025075a4fd (patch) | |
tree | b5b559ec735dee3245de203cb592e93190b79409 /src | |
parent | 97f12207121d4e3171c5ef07d8098f06fb509f67 (diff) | |
download | svg.js-e04f8d1b3595c65e245465606e3987025075a4fd.tar.gz svg.js-e04f8d1b3595c65e245465606e3987025075a4fd.zip |
Added loop(), switched to requestAnimFrame, bumped to v0.38
Diffstat (limited to 'src')
-rwxr-xr-x | src/fx.js | 41 |
1 files changed, 35 insertions, 6 deletions
@@ -153,9 +153,9 @@ SVG.extend(SVG.FX, { , duration: d } - /* start animation */ - fx.interval = setInterval(function(){ - + /* render function */ + fx.render = function(){ + if (fx.situation.play === true) { // This code was borrowed from the emile.js micro framework by Thomas Fuchs, aka MadRobby. var time = new Date().getTime() @@ -169,12 +169,25 @@ SVG.extend(SVG.FX, { if (fx._plot) element.plot(new SVG.PointArray(fx._plot.destination).settle()) - clearInterval(fx.interval) - fx._after ? fx._after.apply(element, [fx]) : fx.stop() + if (fx._loop === true || (typeof fx._loop == 'number' && fx._loop > 1)) { + if (typeof fx._loop == 'number') + --fx._loop + fx.animate(d, ease, delay) + } else { + fx._after ? fx._after.apply(element, [fx]) : fx.stop() + } + + } else { + requestAnimFrame(fx.render) } + } else { + requestAnimFrame(fx.render) } - }, d > fx.situation.interval ? fx.situation.interval : d) + } + + /* start animation */ + fx.render() }, delay || 0) } @@ -323,6 +336,12 @@ SVG.extend(SVG.FX, { return this } + // Make loopable +, loop: function(times) { + this._loop = times || true + + return this + } // Stop running animation , stop: function() { /* stop current animation */ @@ -341,6 +360,7 @@ SVG.extend(SVG.FX, { delete this._cy delete this._size delete this._plot + delete this._loop delete this._after delete this._during delete this._viewbox @@ -446,3 +466,12 @@ SVG.extend(SVG.Element, { // rect.animate(1500, '>').move(200, 300).after(function() { // this.fill({ color: '#f06' }) // }) + + +// Shim layer with setTimeout fallback by Paul Irish +window.requestAnimFrame = (function(){ + return window.requestAnimationFrame || + window.webkitRequestAnimationFrame || + window.mozRequestAnimationFrame || + function (c) { window.setTimeout(c, 1000 / 60) } +})()
\ No newline at end of file |