diff options
author | wout <wout@impinc.co.uk> | 2013-01-03 21:15:32 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2013-01-03 21:15:32 +0100 |
commit | 6f49a9d4c5ada0b7335c08fbcef623cf32898938 (patch) | |
tree | 560c92b904ae232089874507bde65adaaf2f4d80 /src/sugar.js | |
parent | 0da8f1d9c9794155c29b8e8f9a0b5ca940061033 (diff) | |
download | svg.js-6f49a9d4c5ada0b7335c08fbcef623cf32898938.tar.gz svg.js-6f49a9d4c5ada0b7335c08fbcef623cf32898938.zip |
Added the SVG.FX module for animations
Diffstat (limited to 'src/sugar.js')
-rw-r--r-- | src/sugar.js | 47 |
1 files changed, 41 insertions, 6 deletions
diff --git a/src/sugar.js b/src/sugar.js index 47ab35a..c6b5c75 100644 --- a/src/sugar.js +++ b/src/sugar.js @@ -45,13 +45,9 @@ SVG.extend(SVG.Shape, { SVG.extend(SVG.Element, { // rotation - rotate: function(d, x, y) { - var b = this.bbox(); - + rotate: function(d) { return this.transform({ - rotation: d || 0, - cx: x == null ? b.cx : x, - cy: y == null ? b.cx : y + rotation: d || 0 }); }, @@ -96,5 +92,44 @@ SVG.extend(SVG.Text, { }); +// add methods to SVG.FX +if (SVG.FX) { + // add sugar for fill and stroke + ['fill', 'stroke'].forEach(function(m) { + SVG.FX.prototype[m] = function(o) { + var a, k; + + for (k in o) { + a = k == 'color' ? m : m + '-' + k; + this.attrs[a] = { + from: this.target.attrs[a], + to: o[k] + }; + }; + + return this; + }; + }); + + SVG.extend(SVG.FX, { + + // rotation + rotate: function(d) { + return this.transform({ + rotation: d || 0 + }); + }, + + // skew + skew: function(x, y) { + return this.transform({ + skewX: x || 0, + skewY: y || 0 + }); + } + + }); +} + |