Quantcast
Viewing all articles
Browse latest Browse all 55

Answer by HoldOffHunger for dragexit vs dragleave - which should be used?

The MDN web documents you cite are indeed correct. Dragexit is when a dragging and the cursor is "outside of the selected target", whereas Dragleave fires when dragging and the cursor "leaves."

If you drag your cursor slowly, then it goes is displacing pixel-by-pixel (i.e. a straight line): i.e., your cursor might be at position 500x500, 500x501, 500x502, etc.. If you drag your cursor fast, it might displace by multiple pixels: i.e., your cursor might be at position 500x500, then at 500x510, then at 500x520.

If your cursor moves outside of the element and doesn't touch the boundary of the element, then the DragLeave event will not fire, but the DragExit event will fire. For this reason, I usually just bind both events to the same handler, to get the absolute outcome.

Works for me on Chrome (v. 103.0.5060.134). To test, try dragging and dropping really fast, as that is the only way to produce the error of DragLeave not firing when you actually leave the element. But to be clear, drag and drop in HTML isn't something that I would consider stable across all browsers. (After all, what's your top 5 favorite sites that use drag and drop with their elements? Can you even think of 1?)


Viewing all articles
Browse latest Browse all 55

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>