HTML5: dragover(), drop(): how get current x,y coordinates?

后端 未结 2 1153
我寻月下人不归
我寻月下人不归 2020-12-01 09:22

How does one determine the (x,y) coordinates while dragging \"dragover\" and after the drop (\"drop\") in HTML5 DnD?

I found a webpage that describes x,y for dragove

2条回答
  •  半阙折子戏
    2020-12-01 10:13

    The properties clientX and clientY should be set (in modern browsers):

    function drag_over(event) {
        console.log(event.clientX);
        console.log(event.clientY);
        event.preventDefault();
        return false;
    }
    function drop(event) {
        console.log(event.clientX);
        console.log(event.clientY);
        event.preventDefault();
        return false;
    }
    

    Here's a (somewhat) practical example that works in Firefox and Chrome.

提交回复
热议问题