Here's something I'm working on: for a click on a given
element, I want to be able capture the x/y coordinates of the mouse --
that is, the mouse coordinates relative to the top left corner of said
element.
So far, here's what I've got:
http://weston.canncentral.org/misc/w...Haven/pie.html
(Code for the function given in this post below).
It seems to work in Gecko-based browsers, and IE/Win.
It breaks badly in Safari, grabbing what is apparently instead the
viewport position of the mouse. Also, on IE/Mac, it breaks if there's
any scrolling done on the page (try resizing the window so that it's
smaller than the sample image, then scrolling down, and then clicking).
Any ideas what I can do to make it work better for the Mac
browsers? Also, any other platforms which you observe it
breaking under?
Thanks,
Weston
function getClickCoordsW ithinTarget(eve nt)
{
var coords = { x: 0, y: 0};
if(!event) // then we're in a non-DOM (pro'ly IE) browser
{
event = window.event;
coords.x = event.offsetX;
coords.y = event.offsetY;
}
else // we assume DOM modeled javascript
{
var Element = event.target ;
var CalculatedTotal OffsetLeft = 0;
var CalculatedTotal OffsetTop = 0 ;
while (Element.offset Parent)
{
CalculatedTotal OffsetLeft += Element.offsetL eft;
CalculatedTotal OffsetTop += Element.offsetT op;
Element = Element.offsetP arent ;
}
coords.x = event.pageX - CalculatedTotal OffsetLeft;
coords.y = event.pageY - CalculatedTotal OffsetTop;
}
return coords;
}
~==~
http://weston.canncentral.org/
Taking Pictures During Dreams
weston8[at]cann8central.or g
(remove eights to mail me)
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!