How does js distinguish between mouse clicks and long press and drop?

the requirement is to show the editing logic when clicked and the drag logic when the mouse is pressed and dragged. How to distinguish between the two?

Mar.21,2021

Click is the click event, and drag and drop is the dragstart/dragend/mousemove event. Will not confuse


my understanding is

Click is mouse down, click is mousedown+mouseup
drag is mouse down, move, lift (mousedown+mousemove+mouseup)

onmousedown and onmouseup events, they have trigger time respectively. Compare this time, and there is also the x y of the mouse. If you just click on, x y, it should be the same in mouseup and down, but the time interval of dragging is not only long, but also there is a numerical difference in x answer y, because of the shift


do not use click, to judge all in mouseup. If there is a displacement, the drag-related event is performed. If there is no shift, execute the relevant events


to obtain the event.timeStamp, comparison timestamp in the functions of mousedown and mouseup, respectively, and judge how long it takes to press long, and how long it takes to click

.
Menu