HTML5 programming example 3: Drag and Drop preview of image text (txt)

Source: Internet
Author: User
<! Doctype HTML> 
Main code parsing

The style part is simple.

Dragover, dragend, and drop are three drag-and-drop events.

Dragover indicates that the drag-and-drop element is moving within the range of the element.

Dragend indicates that the drag-and-drop operation is complete.

Drop indicates that other elements are dragged to the base element.

The code first listens to these events, cancels the default behavior of the browser, and then uses the file and filereader in html5.

If the file is an image, use the readasdataurl method of filereader to read the image as a dataurl string and store it in the memory and display it in the div.

If the file is TXT text, use the readastext method of filereader to read the file as text (in UTF-8 format by default), put it in memory, and then display it in Div.

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.