Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   finding position of a mouse click, using Mozilla (http://www.velocityreviews.com/forums/t916685-finding-position-of-a-mouse-click-using-mozilla.html)

Nick Wedd 03-01-2005 10:25 AM

finding position of a mouse click, using Mozilla
 
I have this
<DIV id="canopy" onClick="myhandler(event.x,event.y); return false;">
<IMG border=0 height=66 width=292 src="gifs/top.gif">
</DIV>
which works in IE. myhandler gets called with the coordinates of where
the mouse was clicked relative to the <HTML>, and I know where my DIV
is, so I can calculate which part of the image was clicked on.

But with Mozilla, I can't use event.x and event.y, only event.screenX
and event.screenY. These are relative to the whole screen, and so are
affected by the positioning of the browser window and the amount of
browser chrome, so I can't translate them to the frame of my image.

Is there a simple way to deal with this? A Google search leads me to
pages like http://www.mozilla.org/docs/events.html which I am not able
to understand.

The best I can come up with is to create a bunch of empty ("visible" but
transparent) layers that sit in front of my "canopy" layer and catch the
mouse clicks.

Nick
--
Nick Wedd nick@maproom.co.uk

Tomasz Cenian 03-01-2005 11:03 AM

Re: finding position of a mouse click, using Mozilla
 
Nick Wedd napisaƂ(a):
> I have this
> <DIV id="canopy" onClick="myhandler(event.x,event.y); return false;">
> <IMG border=0 height=66 width=292 src="gifs/top.gif">
> </DIV>


You surely missed
event.clientX, event.clientY.

Do not use event.x - its obsolete and IE only.


--
tomasz cenian tcenian at wa dot home dot pl
:::: :: : : http://cenian.boo.pl : : :: ::::

Nick Wedd 03-01-2005 11:31 AM

Re: finding position of a mouse click, using Mozilla
 
In message <42244bff$1@news.home.net.pl>, Tomasz Cenian <aaa@bb.cc.dd>
writes
>Nick Wedd napisa0 >> I have this
>> <DIV id="canopy" onClick="myhandler(event.x,event.y); return false;">
>> <IMG border=0 height=66 width=292 src="gifs/top.gif">
>> </DIV>

>
>You surely missed
>event.clientX, event.clientY.
>
>Do not use event.x - its obsolete and IE only.


Great! Thanks very much for the advice.

Nick
--
Nick Wedd nick@maproom.co.uk

RobG 03-01-2005 11:04 PM

Re: finding position of a mouse click, using Mozilla
 
Nick Wedd wrote:
> I have this
> <DIV id="canopy" onClick="myhandler(event.x,event.y); return false;">
> <IMG border=0 height=66 width=292 src="gifs/top.gif">
> </DIV>
> which works in IE. myhandler gets called with the coordinates of where
> the mouse was clicked relative to the <HTML>, and I know where my DIV
> is, so I can calculate which part of the image was clicked on.
>
> But with Mozilla, I can't use event.x and event.y, only event.screenX
> and event.screenY. These are relative to the whole screen, and so are
> affected by the positioning of the browser window and the amount of
> browser chrome, so I can't translate them to the frame of my image.
>
> Is there a simple way to deal with this? A Google search leads me to
> pages like http://www.mozilla.org/docs/events.html which I am not able
> to understand.


The section of the Mozilla site you were after is:

*DOM Reference*:
<URL:http://www.mozilla.org/docs/dom/domref/>

*Event Reference*

<URL:http://www.mozilla.org/docs/dom/domref/dom_event_ref.html#998197>

Where you will find references to W3C DOM properties clientX/Y
and screenX/Y and the older, non-W3C layerX/Y, pageX/Y.

If you are doing stuff with coordinates, the "Viewport" link at
quirksmode.org is an invaluable reference:

<URL:http://www.quirksmode.org/index.html>


--
Rob


All times are GMT. The time now is 02:28 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.