问题
Hi i'm implementing a visual editor where users are allowed to drag images onto the page, and drag other images inside these previously dragged images (kind of 'add another image').
I basically only need the mouse coordinates during the drag: the element hiliting etc... i do with custom functions based on these coordinates.
The problem is, while on Webkit I can get them with event.clientX and event.clientY, under Firefox (v.16.0.1 OSX) their 'counterparts' pageX and pageY are always zero in my experience during a drag.
However, they are not Zero during a mouseMove.
Smart as I am, I did a
$(document).on("mouseMove",function(e){_PX=e.pageX,_PY=e.pageY})
to always have the latest PageX and PageY so I could use them inside the onDrag handler but ...
the OnMouseMove does not fire during a Drag And Drop operation :( :(
Is there any way I can get the Mouse X and Y during a DnD? I'd like not to clutter very much my code, as it should (and already does) work in different platforms but on firefox.
Can anybody give me some pointers? Thanx in advance.
回答1:
sorry, I found the answer here:
How do I get clientX and clientY to work inside my "drag" event handler on Firefox?
I've solved it like this:
(___NODRAGEVENT=$.browser.mozilla)
&& $(document)
.on("dragover",function(e) {
e=e.originalEvent;
___PAGEX=e.clientX||e.pageX;
___PAGEY=e.clientY||e.pageY;
});
I'm really surprised and confused that onDragOver DOES include clientX and clientY. Why the **** don't they populate them to the ondrag event?
来源:https://stackoverflow.com/questions/13110349/firefox-ondrag-pagex-pagey-always-zero