diff options
author | wout <wout@impinc.co.uk> | 2014-02-01 20:13:05 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2014-02-01 20:13:05 +0100 |
commit | 11376f6ec53092bd3893a168f25a08983d7aff6c (patch) | |
tree | de6a4725bb791549a3e177ec06b0364e913f5659 /src/number.js | |
parent | a19bbab549b2d65b83751c3ef85295ee02065f42 (diff) | |
download | svg.js-11376f6ec53092bd3893a168f25a08983d7aff6c.tar.gz svg.js-11376f6ec53092bd3893a168f25a08983d7aff6c.zip |
added `morph()` and `at()` methods to `SVG.Number` for unit morphing
Diffstat (limited to 'src/number.js')
-rwxr-xr-x | src/number.js | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/src/number.js b/src/number.js index 2b3b147..7218a50 100755 --- a/src/number.js +++ b/src/number.js @@ -45,13 +45,6 @@ SVG.extend(SVG.Number, { valueOf: function() { return this.value } - // Convert to different unit -, to: function(unit) { - if (typeof unit === 'string') - this.unit = unit - - return this - } // Add number , plus: function(number) { this.value = this + new SVG.Number(number) @@ -74,5 +67,29 @@ SVG.extend(SVG.Number, { return this } + // Convert to different unit +, to: function(unit) { + if (typeof unit === 'string') + this.unit = unit + + return this + } + // Make number morphable +, morph: function(number) { + this.destination = new SVG.Number(number) + + return this + } + // Get morphed number at given position +, at: function(pos) { + /* make sure a destination is defined */ + if (!this.destination) return this + + /* generate morphed number */ + return new SVG.Number(this.destination) + .minus(this) + .times(pos) + .plus(this) + } })
\ No newline at end of file |