How do I get clientX and clientY to work inside my “drag” event handler on Firefox?

后端 未结 3 1112
我在风中等你
我在风中等你 2021-01-05 00:13

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 o

相关标签:
3条回答
  • 2021-01-05 00:33

    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.

    0 讨论(0)
  • 2021-01-05 00:50

    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.

    But why do something like this, aren't there libraries like JQuery & Prototype available for cross browser drag & drop?

    Or else if you want to implement a DD library of your own, you can take help of their methods or extend them, as both the libraries are following object oriented paradigm.

    This will save much time.

    0 讨论(0)
  • 2021-01-05 00:51

    The drag event in HTML 5 is not fully functional in todays browsers. To simulate a drag n drop situation you should use:

    1. Add a onmousedown event, setting a var true.
    2. Add a onmouseup event, setting that var false.
    3. Add a onmousemove event, checking if that var is true, and if it is, move your div according to the coordinates.

    This always worked for me. If you face any problems, get in touch again, I can provide some examples.

    good luck!

    0 讨论(0)
提交回复
热议问题