how to get dynamically the x & y values of a raphael js element even after a zoom or a left or right move, I want to show a div near to my element, when I show the element.getBBox() values I found that they don't change even if I move the element or I zoom in/out, my code that I use to get x & y values seems like this :
x = (myElement.getBBox().x+myElement.getBBox().x2)/2;
x+=$("#container").offset().left;
y = (myElement.getBBox().y+myElement.getBBox().y2)/2;
y+=$("#container").offset().left;
and the code that moves my div (a tooltip) is :
$("#myTooltip").css({"left":x+"px","top":y+"px"}).show();
Note : it works when I do the same thing with mouse coordinates (using x=e.pageX;y=e.pageY;) but in this case I want to do it when I click on another button in the page
thank's in advance
I am also using Raphael and came across to what I think you need in your project.
In order to understand how x and y can be shown dynamically, look at this DEMO:
While you are dragging objects around, you can see their coordinates change dynamically. Good Luck
The solution is to use myElement.attr('x') and myElement.attr('y') instead of myElement.getBBox().x and myElement.getBBox().y, thank you A.S. Roma, don't forget to say hello to Totti
Edit :
if someone have the same problem, the best solution I found untill now is to use jquery and raphael, explication :
First of all I need in the definition of the element to add an ID like this : myElement.node.id='myUniqueId' and after that you can access to the element using jquery like this x = $("#myUniqueId").offset().left and y = $("#myUniqueId").offset().top
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With