DataTransfer object: The medium that the object is used to pass, used generally as event.datatransfer.
Draggable Property: is the label element to set the draggable=true, otherwise it will not have effect
For example:
<div title="拖拽我" draggable="true">列表1</div>
- ondragstart Event: An event that is triggered when a drag element starts being dragged, and this event acts on the dragged element
- OnDragEnter Event: An event that fires when a dragged element enters the target element, which acts on the target element
- OnDragOver Event: An event that is triggered when a drag element is moved on the target element, which acts on the target element
- OnDrop Event: The dragged element on the target element with the mouse release of the triggered event, which acts on the target element
- ondragend Event: An event triggered when a drag is completed, which acts on the dragged element
- Event.preventdefault () method: Prevents execution of the default event methods. Be sure to do it in OnDragOver.
- preventdefault (), otherwise the OnDrop event will not be triggered. In addition, if you are dragging things from other applications or files, especially images, the default action is to display the image or related information, not to actually perform the drop. At this point, you need to use the document OnDragOver event to kill it directly.
- event.effectallowed Property: Is the effect of drag and drop.
Here is an example of dragging and dropping an external program picture:
HTML code:
<form id="frm"> <fieldset> <legend>To select a file by dragging:</legend> <ul id="Upload" ondrop="Dropfile (event)" OnDragEnter ="return false;" ondragover="return false;" ></ul> </fieldset></form>
JS Code:
<script type="Text/javascript"> function $(ID){ returndocument.getElementById (ID); } function loadfun(file){ return function(e){ varStr=document.createelement (' span '); str.innerhtml=[' ', E.target.result,' "title=" ', File.name,'/> '].join ("'); $(' upload '). insertbefore (str,NULL); } }; function uploadfile(f){ if(typeoffilereader==' undefined ') {alert (' Browser does not support FileReader objects ')return false; } for(varI=0; i<f.length;i++) {varReader=NewFileReader (); Reader.readasdataurl (F[i]); Reader.onload=loadfun (F[i]); } } function dropfile(e){UploadFile (E.datatransfer.files); E.stoppropagation (); E.preventdefault (); }</script>
Effects such as:
Introduction to drag & drop drag and drop