How to move raphael set?

bozhidarc picture bozhidarc · Jan 13, 2012 · Viewed 9.5k times · Source

I have a set of objects grouped with Raphael.set(). What I want to do is to move the whole set (change x and y coordinates) from one place to another. How I can move the whole set as a single object? What I found already is that when an .attr({X: newX, Y: newY}) is called every element from the set will be positioned on this coordinated which will result in piling all the elements in one place.

Answer

methodofaction picture methodofaction · Jan 13, 2012

Edit: Refer to Rick Westera's answer as translate is now deprecated.

Use .translate(x, y), example:

var paper = Raphael('stage', 300, 300);
var set = paper.set();
set.push(paper.rect(0,0,30,50));
set.push(paper.circle(40,50,10));
set.push(paper.path("M 0 70 L 100 70"));
set.translate(100, 100);

http://jsfiddle.net/q4vUx/