views:

32

answers:

2

How can I get the position of an object in Raphael? I can get the size using getBBox(), but there appears to be no way to get the position?

A: 

Depending on what kind of shape it is, the documentation seems to say it can be accessed using the .attr() function. So, if it's a circle...

var x = myCircle.attr('cx'); //cx is the center-x-coordinate of the circle
var y = myCircle.attr('cy'); //same, for y
var r = myCircle.attr('r'); //Radius of circle.

A square would have attrs of x, y, width, height. Check the documentation for more info.

clarkf
el.getBBox is the correct approach. Please see Dmitry's answer.
echo-flow
+1  A: 

getBBox() should give you position as well as x and y properties.

var bbox = el.getBBox();
alert([bbox.x, bbox.y]);
Dmitry Baranovskiy