I want to know the difference of dragover
and dragenter
events of HTML5 drag &drop.
I'm not clear about the difference.
The ondrop event occurs when a draggable element or text selection is dropped on a valid drop target. Drag and drop is a very common feature in HTML5. It is when you "grab" an object and drag it to a different location.
Drag and Drop (DnD) is powerful User Interface concept which makes it easy to copy, reorder and deletion of items with the help of mouse clicks. This allows the user to click and hold the mouse button down over an element, drag it to another location, and release the mouse button to drop the element there.
The DragEvent interface is a DOM event that represents a drag and drop interaction. The user initiates a drag by placing a pointer device (such as a mouse) on the touch surface and then dragging the pointer to a new location (such as another DOM element).
The dragenter event happens at the moment you drag something in to the target element, and then it stops. The dragover event happens during the time you are dragging something until you drop it.
Look here:
$('.dropzone').on("dragover", function (event) {
console.log('dragover');
});
$('.dropzone').on("dragenter", function (event) {
console.log('dragenter');
});
Now see the console:
As you can see the dragenter happen once (when you drag element in to the target).
But the dragover event happen every few hundred milliseconds.
The same difference exist between drag and dragstart, dragstart happen once but drag happen every few hundred milliseconds.
Based on the dragenter
and dragover
MDN doc...
dragover
The dragover event is fired when an element or text selection is being dragged over a valid drop target (every few hundred milliseconds).
dragenter
The dragenter event is fired when a dragged element or text selection enters a valid drop target.
The dragover
is triggered after a small delay (every 350 ms, I think) while the cursor stays over the element.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With