Introduction to drag & drop drag and drop

Source: Internet
Author: User
Tags dropfile

    1. DataTransfer object: The medium that the object is used to pass, used generally as event.datatransfer.

    2. 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>
    1. ondragstart Event: An event that is triggered when a drag element starts being dragged, and this event acts on the dragged element
    2. OnDragEnter Event: An event that fires when a dragged element enters the target element, which acts on the target element
    3. OnDragOver Event: An event that is triggered when a drag element is moved on the target element, which acts on the target element
    4. OnDrop Event: The dragged element on the target element with the mouse release of the triggered event, which acts on the target element
    5. ondragend Event: An event triggered when a drag is completed, which acts on the dragged element
    6. Event.preventdefault () method: Prevents execution of the default event methods. Be sure to do it in OnDragOver.
    7. 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.
    8. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.