Locate the mouse on the image

how to determine the location of the mouse in the image using javascript on mouse click

+3
source share
2 answers

cropped version of geeketteSpeaks-related solution:

<html>
<head>
<script type="text/javascript">
    function getImageCoords(event,img) {
        var posX = event.offsetX?(event.offsetX):event.pageX-img.offsetLeft;
        var posY = event.offsetY?(event.offsetY):event.pageY-img.offsetTop;
        alert("You clicked at: ("+posX+","+posY+")");
    }
</script>
</head>
<body>
    <img src="image.jpg" onclick="getImageCoords(event,this);">
</body>
</html>
+7
source

Source: https://habr.com/ru/post/1769822/


All Articles