I am currently working on html5 drag and drop. My code is working however, I want to change one effect. When user drags an element then a copy of dragged element should stick to cursor/pointer/arrow. The default behaviour of html5 drag and drop does not look real. If you see jquery UI draggable, the element literally moves with cursor. How can I add this kind of effect with html5 drag and drop?
Below is my code.
html code
<div id="boxA">
<div id="word1" class="word" draggable="true">HTML5</div>
<div id="word2" class="word" draggable="true">is</div>
<div id="word3" class="word" draggable="true">very</div>
<div id="word4" class="word" draggable="true">useful</div>
<div id="word5" class="word" draggable="true">indeed</div>
</div>
<div id="boxB"></div>
javascript
$('.word').on('dragstart', dragDefine);
$('#boxA').on('dragover', dragOver);
$('#boxA').on('drop', dragDrop);
$('#boxB').on('dragover', dragOver);
$('#boxB').on('drop', dragDrop);
function dragDefine(ev) {
ev.originalEvent.dataTransfer.effectAllowed = 'move';
ev.originalEvent.dataTransfer.setData("text/plain", ev.target.getAttribute('id'));
ev.originalEvent.dataTransfer.setDragImage(ev.target, 0, 0);
return true;
}
function dragOver(ev) {
ev.preventDefault();
}
function dragDrop(ev) {
var idDrag = ev.originalEvent.dataTransfer.getData("Text");
ev.target.appendChild(document.getElementById(idDrag));
ev.preventDefault();
}