Been stuck on this for a while. I can find the cursor position on a mouse move like this:
function myMoveFunction()
{
document.getElementById("ImageCaption").innerHTML = "Coords: " + event.x + ", " + event.y ;
}
<asp:ImageButton id="imagebutton1" runat="server" Width="512" Height="262"
ImageUrl="DrawRoom.aspx?v=0"
OnClick="ImageButton_Click"
onmousemove="myMoveFunction()" />
<p><span id="ImageCaption"></span></p>
And this gives me the position relative to the window very handily, but I need to subtract the position of the image. I've found lots of code which returns me blankness.
function FindPosition(oElement) {
if (typeof (oElement.offsetParent) != "undefined") {
for (var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent) {
posX += oElement.offsetLeft;
posY += oElement.offsetTop;
}
return [posX, posY];
}
else {
return [oElement.x, oElement.y];
}
}
function myMoveFunction()
{
var pos = FindPosition(document.getElementbyID("imagebutton1"));
document.getElementById("ImageCaption").innerHTML = "Coords: " + pos[0]+ ", " + pos[1] ;
}
Gives me only blank in my imagecaption