search

Home  >  Q&A  >  body text

javascript - When using H5 drag and drop, why is the dragged element removed?

1. Please see the phenomenon:
https://codepen.io/xuyu/proje...

2. The effect I want to achieve is to copy the dragged element to the specified area without deleting the dragged element.

ringa_leeringa_lee2716 days ago960

reply all(1)I'll reply

  • 阿神

    阿神2017-06-22 11:55:56

    document.addEventListener("drop", function( event ) {

      // prevent default action (open as link for some elements)
      event.preventDefault();
      // move dragged elem to the selected drop target
      if ( event.target.className == "landingArea" ) {
          event.target.style.background = "";
          //dragged.parentNode.removeChild( dragged );
          $(event.target).append($(dragged).clone().css('opacity', 1))
      }

    }, false);

    reply
    0
  • Cancelreply