HTML5 drag files to the target area to upload files

Source: Internet
Author: User

Drag this HTML5 API on the PC side of the support rate is still pretty high, there are 99.97%

;

This API has two drag events for "dragged element" and "drop target area"

Dragged elements:
##1.  dragstart   这个事件触发在用户按下鼠标开始拖动这个元素或者文本选中的时候##2. drag   当用户拖动一个元素或者文本时候, 随时都会触发的事件.##3. dragend  发生在用户释放鼠标或者按了ESC键的时候触发### 对应的支持一些属性和方法, 详细的请看  
Drop target Area
# 1. drapenter  发生在一个元素或者一个文本进入目标区域时候发生# 2. drapover   触发drapenter 以后随即触发dragover , 只要拖动的元素在目标区域移动就会触发,这个事件会持续触发. (个人的理解是,先有了进入目标区域,然后在须发drapver);# 3. drapleave  跟drapenter对应的就是离开这个目标区域触发的事件.

# 4. Drop releases the mouse trigger event in the target area. (Special attention here, this is the drop!!! not drap);

It is also important to note that the DragOver and drop events trigger the browser's default event. For example, if you drag a picture or text, the browser opens a new window. A drag event will have a property called. "" DataTransfer "", this property exists when the event is dragged and dropped. The DataTransfer object has a SetData (format, data) (the first parameter is the datatype, where IE defines only two valid data types: "Text" and "URL"; the second argument is a string that represents the data to be passed.) ) and GetData (format) (in the drop event, call the GetData () function for the drop target to get the data passed in.

The first parameter is the data type set in the SetData () method. There is also a files property that gets some relevant parameters for the property here to point out that you want to access information about a file, you need to: Event.datatransfer.files[0]. See figure in detail.

The following is a simple demo based on what you see.

<!    DOCTYPE html>

In addition to more detailed information, you can view the https://www.cnblogs.com/libin-1/p/5857714.html

HTML5 drag files to the target area to upload files

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.