Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pageX and pageY are always set to 0 in Firefox during the ondrag event

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 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 my code too much, as it already works on different platforms but not on Firefox.

like image 417
rupps Avatar asked Oct 28 '12 15:10

rupps


1 Answers

I found the answer here.

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 don't they populate them on the drag event?

like image 131
rupps Avatar answered Nov 14 '22 21:11

rupps