vadnica-logo
X

JavaScript HTML DOM Events: dragover

The dragover event fires when a dragged item hovers over a target element. The crucial step is event.preventDefault() – without it the drop on the target will not work. You can also set dataTransfer.dropEffect (e.g., “move”, “copy”) to indicate to the user what will happen on drop.

EXAMPLE
RESULT
  1. Drag one of the cards (A–D) into the target area on the right.
  2. On dragstart the dataTransfer (text/plain with the card ID) is set and the card gets a visual “dragging” cue.
  3. During dragover you call event.preventDefault() (this enables drop) and suggest a dropEffect:
    1. without modifiers: move,
    2. with Ctrl or ⌘ (Meta): copy.
  4. dragenter/dragleave add/remove a subtle highlight on the target (visual feedback).
  5. On drop the card:
    1. moves (move) into the target, or
    2. copies (copy) if you hold Ctrl/Meta while dropping.
  6. The “Clear log” button empties the output, and “Reset” refreshes the demo (returns everything to its initial state).
Card A
Card B
Card C
Card D
Target: hover over me (dragover) and drop me (drop)
Hint: hold Ctrl for suggested copy, otherwise move.


Thank you for visiting! Adding privacy policy.

© 2024 All rights reserved.

Vam je koda pomagala? Če želite podpreti moj trud pri pripravi vodičev in vzdrževanju strani, mi lahko namenite donacijo za kavo.