如何让 clientX 和 clientY 在我的“拖动"中工作?Firefox 上的事件处理程序?
Mozilla Firefox 3.x 在收听ondrag"时似乎有一个错误.事件.事件对象不报告被拖动对象的位置,clientX
、clientY
等屏幕偏移量均设置为零.
Mozilla Firefox 3.x seems to have a bug when listening to the "ondrag" event. The event object doesn't report the position of the object being dragged, clientX
, clientY
, and other screen offsets are all set to zero.
这是相当有问题的,因为我想根据被拖动的元素制作一个代理元素,当然使用 clientX
和 clientY
来调整它的位置.
This is quite problematic as I wanted to make a proxy element based on the element being dragged and using of course, clientX
and clientY
to adjust its position.
我知道有一些很酷的东西,例如 HTML5 中的 setDragImage
,但我想为浏览器之间的原生 DD 提供一个通用抽象.
I know that there's cool stuff around such as setDragImage
in HTML5 but I want to provide a generic abstraction for native DD between browsers.
错误代码:
document.addEventListener('drag', function(e) {
console.log(e.clientX); // always Zero
}, false);
注意:
此问题不会发生在其他事件(dragstart
、dragover
)上,并且在拖动某些东西时无法捕获 mousemove
事件.
This problem doesn't happen on other events (dragstart
, dragover
) and the mousemove
events cannot be captured while dragging something.
推荐答案
我找到了一个解决方案,我在文档级别的dragover"事件上放置了一个监听器,现在我得到了我想要的正确的 X 和 Y 属性可以通过全局共享对象公开.
I found a solution, I've placed a listener on the "dragover" event at the document level, now I get the right X and Y properties that I can expose through a globally shared object.
相关文章