Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Element Position Coordinates

Status
Not open for further replies.

Jeremy21b

Technical User
Jul 7, 2002
127
CA
Hello.

I have an centered image that I am allowing users to crop via a custom asp script. The script requires four coordinates. How can I find the position of the mouse relative to the picture instead of relative to the screen? People are telling me to use pixelLeft/pixelTop but that only works if you define the image position. Is there any way I can get around this? Thanks.
 
Use mouse events tracking.
Find a script that does it (there are lots of them available), and then add this:

function init()
{
document.getElementById("theImage").onmousemove = trackMouse;
document.getElementById("theImage").onmouseup = MouseEvent;
}

where "theImage" is an ID of the desired image.

This will make mouse events enabled and it's cursor coordinates will be given relative to the image.

Note that this function should be added to body onload event:
<body ... onload=&quot;init()&quot;>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top