Get the x, y coordinate's relative to a mouseclick in Dojo/Javascript
I have a image that has a dojo touch event (similar to mouseclick). I want to get the x and y coordinate's relative to the div. Right now I am getting the canvasX and canvasY property. It looks like offsets will solve my problem. How can I get it to work with javascript, or if dojo has some offset functi开发者_如何学编程on?
If I understand the question correctly, you want to get the X,Y which your starting point is the image (not the whole document).
See if this example works for you
<div style="margin-left: 500px; border: 1px black solid;">
<div style="border: 1px blue solid;">
<img src="http://ecdn3.hark.com/images/000/000/294/294/original.jpg"
onclick="getOffsets(event, this);"/>
</div>
</div>
<script>
function getOffsets(event, img)
{
var relativeX = event.clientX - img.offsetLeft;
var relativeY = event.clientY - img.offsetTop;
alert(relativeX + " " + relativeY);
}
</script>
精彩评论