Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-04-2006, 10:14 AM   PM User | #1
dannyspencer
New to the CF scene

 
Join Date: Aug 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
dannyspencer is an unknown quantity at this point
Question getting mouse coords onclick relative to image

Hi there,

I am trying to create a javascript that will return the coords of where the mouse clicked on an image. I know there are script that will do this sort of thing but they always return the value relative to the whole document (top left of browser screen is 0,0) i would like the coordinates relative to the image (topleft of image is 0,0)

Can anyone help??

Dan
dannyspencer is offline   Reply With Quote
Old 08-04-2006, 10:47 AM   PM User | #2
vwphillips
Senior Coder

 
Join Date: Mar 2005
Location: Portsmouth UK
Posts: 4,358
Thanks: 3
Thanked 459 Times in 446 Posts
vwphillips is a jewel in the roughvwphillips is a jewel in the roughvwphillips is a jewel in the rough
number of ways

one
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
  <title></title>
<script language="JavaScript" type="text/javascript">
<!--

function zxcEvent(){
 var zxce=window.event||arguments.callee.caller.arguments[0];
 if (typeof zxce.layerX=='undefined') zxce.layerX=zxce.offsetX;
 if (typeof zxce.layerY=='undefined') zxce.layerY=zxce.offsetY;
 alert('Left: '+zxce.layerX+'\nTop: '+zxce.layerY);
 return [zxce.layerX,zxce.layerY];
}


//-->
</script>
</head>

<body>
<div style="position:relative;left:100px;top:100px;width:100px;height:100px;background-color:red;" onmousedown="zxcEvent();" ></div>
</body>

</html>
__________________
Vic

God Loves You and will never love you less.

http://www.vicsjavascripts.org.uk/

If my post has been useful please donate to http://www.operationsmile.org.uk/
vwphillips is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:55 AM.


Advertisement
Log in to turn off these ads.