I'm trying to animate an svg object with jQuery. The animation should be something like this:
- click on the primary object -> translate the primary object up.
- click on another object -> translate the primary object in another way starting from the actual position.
Look at this http://jsfiddle.net/MaxMarkson/khZqW/2/
$('#ellipseRed').click(function() {
$(this)
.css({"min-height": 0})
.animate(
{"min-height": -150},
{duration: 1000,
step: function(top){
this.setAttribute("transform", "translate(0,"+top+")");
}
}
);
});
$('#ellipseBlue').click(function() {
// Getting
var xforms = $('#ellipseRed')[0].getAttribute('transform');
var parts = /translate\(\s*([^\s,)]+)[ ,]([^\s,)]+)/.exec(xforms);
var firstX,firstY;
if(parts == null){
$('#ellipseRed')[0].setAttribute('transform','translate(0,0)');
firstX = 0;
firstY = 0;
}
else{
firstX = parts[1];
firstY = parts[2];
}
// Setting
//
var animation = {};
animation.x = firstX + 200;
animation.y = firstY - 100;
$('#ellipseRed')
.css({"min-height": 0})
.css({"left":0})
.animate(
{"min-height": animation.y},
{"left": animation.x},
{duration: 1000,
step: function(top, left){
this.setAttribute("transform", "translate("+left+","+top+")");
}
}
);
});
The primary object is the red ellipse, the translation applied by clicking on it works fine, the other animation doesn't work and I can't figure out why.
Thank you!