Use JS to make drag

xiaoxiao2021-03-06  40

First let's analyze the steps of towing, first of course, it is your mouse to press the layer to be dragged, then things, you can imagine: it is a mouse

. Finally, drag to the destination, the mouse button is released, dragging the end.

If you read the event driver of this site, you must know that the mouse is triggered by the mousedown event, the event that the mouse is released is Mouseup, and the event drive is implemented.

The method of the function function is obj.οnmοusedοwn = func; canceled method is obj.οnmοusedοwn = null; ok, I know the above knowledge, let us take a look

code: