鼠标单击图像上的位置 [英] Mouse click location on an image

查看:120
本文介绍了鼠标单击图像上的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个GWT容器里面有一些东西,还有一个添加了Clickhandler的图像。



我想要做的是获取确切的鼠标事件相对于图像的X和Y坐标。我看到此处
的帖子,但这是不是我想要的。



据我看到,我有选择像获取图像的绝对位置和事件位置,但这只有在用户不滚动

  event.getNativeEvent()。getClientY() -  image.getElement()。getAbsoluteTop(); 


解决方案

感谢Samuel,



这里是解决方案

  event.getNativeEvent()。getClientY() -  image.getAbsoluteTop )+ Document.get()。getScrollTop()


I have a GWT container with some stuff in it and an image which is added a clickhandler.

What I try to do is to get the exact mouse event's X and Y coordinates relative to the image. I saw the post here but this is not what I want.

As far as I can see, I have option like getting the image absolute location and event location but this works only if the user doesn't scroll down the page.

event.getNativeEvent().getClientY()- image.getElement().getAbsoluteTop();

解决方案

Thanks to Samuel,

here is the solution

event.getNativeEvent().getClientY()- image.getAbsoluteTop() + Document.get().getScrollTop()

这篇关于鼠标单击图像上的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆