我在 div 中添加图像。我想在用户右键单击该图像的位置获取图像的坐标(而不是屏幕的坐标)。我该怎么做?
<div id="Boma" style="width: 1000px; height: 600px; position: relative">
<img src="Boma_1_2/F16_20170316141116392_0001.jpg" alt="Boma" style="width: 1000px; height: 600px;">
</div>
最佳答案
我建议您查看 .offset()
jQuery 函数:
The .offset() method allows us to retrieve the current position of an element (specifically its border box, which excludes margins) relative to the document.
Here是关于在 Javascript 中使用右键单击的非常清楚且有用的评论。
现在您应该拥有所有工具来创建您想要做的事情。希望对您有所帮助。
关于javascript - 通过jquery或javascript获取图片的坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45818046/