드래그 앤 드롭(DnD)은 마우스 클릭의 도움으로 항목을 쉽게 복사, 재정렬 및 삭제할 수 있는 강력한 사용자 인터페이스 개념입니다. 이렇게 하면 사용자가 요소 위에서 마우스 버튼을 클릭한 상태로 다른 위치로 드래그한 다음 마우스 버튼을 놓아 요소를 드롭할 수 있습니다.
드래그 앤 드롭:
<!DOCTYPE HTML>
<html>
<head>
<style>
#boxA, #boxB {float:left;padding:10px;margin:10px; -moz-user-select:none;}
#boxA { background-color: #6633FF; width:75px; height:75px; }
#boxB { background-color: #FF6699; width:150px; height:150px; }
</style>
<script>
function dragStart(ev) {
ev.dataTransfer.effectAllowed='move';
ev.dataTransfer.setData("Text", ev.target.getAttribute('id'));
ev.dataTransfer.setDragImage(ev.target,0,0);
return true;
}
</script>
</head>
<body>
<center>
<h2>Drag and drop HTML5 demo</h2>
<div>Try to drag the purple box around.</div>
<div id = "boxA" draggable = "true"
ondragstart = "return dragStart(ev)">
<p>Drag Me</p>
</div>
<div id = "boxB">Dustbin</div>
</center>
</body>
</html>