Dylan Dylan - 7 months ago 77
Javascript Question

Raphael JS : how to move/animate a path object?

Somehow this doesn't work...

var paper = Raphael("test", 500, 500);

var testpath = paper.path('M100 100L190 190');

var a = paper.rect(0,0,10,10);
a.attr('fill', 'silver');

a.mousedown( function() {
testpath.animate({x: 400}, 1000);

I can move rects this way but not paths, why is that, and how do I move a path object then?!


With the latest version of Raphael, you can do this:

var _transformedPath = Raphael.transformPath('M100 100L190 190', 'T400,0');
testpath.animate({path: _transformedPath}, 1000);

This saves you from the trouble of having to clone a temp object.