如何让 clientX 和 clientY 在我的“拖动"中工作?Firefox 上的事件处理程序? [英] How do I get clientX and clientY to work inside my "drag" event handler on Firefox?

查看:14
本文介绍了如何让 clientX 和 clientY 在我的“拖动"中工作?Firefox 上的事件处理程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Mozilla Firefox 3.x 在收听ondrag"时似乎有一个错误.事件.事件对象不报告被拖动对象的位置,clientXclientY等屏幕偏移量均设置为零.

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.

这是相当有问题的,因为我想根据被拖动的元素制作一个代理元素,当然使用 clientXclientY 来调整它的位置.

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);

注意:

此问题不会发生在其他事件(dragstartdragover)上,并且在拖动某些东西时无法捕获 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.

这篇关于如何让 clientX 和 clientY 在我的“拖动"中工作?Firefox 上的事件处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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