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

问题描述

Mozilla firefox 3.x在听ondrag事件时似乎有一个错误。事件对象不会报告被拖动的对象的位置,clientX,clientY和其他屏幕偏移都被设置为零。这是非常有问题的,因为我想基于被拖动的元素和当然使用clientX和clientY来调整其位置的代理元素。

Mozilla firefox 3.x seems to have a bug when listening to "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. 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)和

Note :This problem doesn't happen on other events (dragstart, dragover) and the mousemove events cannot be captured while dragging somethin'.

请帮助!

推荐答案

我找到一个解决方案,我在文档级别的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上的事件处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 23:46