From e4719d4300f9b5dc549e840c204a2e1c58f0d14c Mon Sep 17 00:00:00 2001 From: kangax Date: Tue, 5 Feb 2013 20:25:17 +0100 Subject: [PATCH] Add support for animating 2nd level object properties --- src/object.class.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/object.class.js b/src/object.class.js index 05a43394..8e334d73 100644 --- a/src/object.class.js +++ b/src/object.class.js @@ -910,7 +910,7 @@ * @method _animate */ _animate: function(property, to, options) { - var obj = this; + var obj = this, propPair; to = to.toString(); @@ -921,12 +921,20 @@ options = fabric.util.object.clone(options); } + if (~property.indexOf('.')) { + propPair = property.split('.'); + } + + var currentValue = propPair + ? this.get(propPair[0])[propPair[1]] + : this.get(property); + if (!('from' in options)) { - options.from = this.get(property); + options.from = currentValue; } if (~to.indexOf('=')) { - to = this.get(property) + parseFloat(to.replace('=', '')); + to = currentValue + parseFloat(to.replace('=', '')); } else { to = parseFloat(to); @@ -939,7 +947,12 @@ easing: options.easing, duration: options.duration, onChange: function(value) { - obj.set(property, value); + if (propPair) { + obj[propPair[0]][propPair[1]] = value; + } + else { + obj.set(property, value); + } options.onChange && options.onChange(); }, onComplete: function() {