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 attr
s of x, y, width, height. Check the documentation for more info.
clarkf
2010-10-25 21:54:30
el.getBBox is the correct approach. Please see Dmitry's answer.
echo-flow
2010-10-27 07:47:46
+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
2010-10-27 06:02:46