tags:

views:

178

answers:

2

I have two div boxes: one that is large is the parent to the other that is small. With propeties offsetX and offsetY, I find out the coorinates of the mouse pointer. I only need coordinates relative to the large box, but when the mouse pointer is over the small box, coordinates are figured out relative to this small box. How do I get coordinates relative to the large box even though the mouse pointer is over the small box?

+1  A: 

I assume that is because the small box is absolutely or relatively positioned (position: absolute position: relative). Can you change that so that only the parent is absolutely positioned?

Otherwise, the JS Frameworks should offer everything you need to convert relative into absolute positions, and correlate them to the mouse cursor.

Pekka
Yes, you are right. The small box is absolutely positioned. Wouldn't there be a way? Frameworks are evil! I know how to, but that's a bit ugly, I think.
David Gore
You would have to add the absolute `left` and `top` coordinates of the parent element of the mouse cursor position. (probably this.parentElement.style.left..)
Pekka
This is one is even worse!
David Gore
Better to deal with x and y if the target get changed.
David Gore
Though, you are right if to do that with the target.
David Gore
A: 

http://javascript.internet.com/page-details/mouse-coordinates.html

tommaso
Are you kidding? There is nothing useful for my case.
David Gore