From this line of code:
event.originalEvent
It seems that you are using jquery? So just think that jquery is easy to use and compatible with your browser.
HTML5 native and jquery method (using only javascript) implementing drag are almost the same. HTML5 only added drag and drop events, but no more to drag and drop methods:
without jquery:
function dragStart(event) { event.originalEvent.dataTransfer.effectAllowed = 'move'; event.originalEvent.dataTransfer.setData("text/plain", event.target);//JUST ELEMENT references is ok here NO ID console.log(event); console.log('Dragging...'); var clone = event.target.cloneNode(true); event.target.parentNode.appendChild(clone); event.target.ghostDragger = clone;//SET A REFERENCE TO THE HELPER $(clone).addClass('dragging');//NOW YOU HAVE A CLONE ELEMENT JUST USE this and remove on drag stop return true; } function dragging(event){ var clone = event.target.ghostDragger; //here set clone LEFT and TOP from event mouse moves } //ON STOP REMOVE HELPER ELEMENT function stopDrag(event){ var clone = event.target.ghostDragger; clone.parentNode.removeChild(clone); }
Using jquery:
$( "#draggable" ).draggable({ helper: "clone",
Althoug I suggest using jquery ui for decoration. With it, you can personalize the drag and drop helper as needed.
albanx
source share