HTML5 drag event notes and html5 drag events

Source: Internet
Author: User

HTML5 drag event notes and html5 drag events

In HTML5 specifications, you can add 'draggable = "true" 'to the element to determine whether the element can be dragged. Images and links are enabled by default.

1. Drag element: the 'draggable = "true" 'element is set.

When an element is dragged, the following events are triggered in sequence:

1. dragstart (when you press the mouse and start to move the mouse, the dragstart event will be triggered on the drag-and-drop element)

2. drag (after the dragstart event is triggered, the drag time is triggered immediately, and the event is continuously triggered when the element is dragged)

3. dragend (when the drag is stopped, the dragend event is triggered no matter whether the element is put to a valid placement target)

2. Target element: Any element on the page can be a target element.

When an element is dragged to a valid target, the following events occur in sequence:

1. dragenter (the dragenter event will be triggered as long as there are element times dragged to the target)

2. dragover (the dragover event is triggered immediately after dragenter is triggered. When the dragged target remains within the target range, the dragover event will be continuously triggered)

3. dragleave or drop (if an element is dragged out of the position target, the dragover event will not be triggered, but will trigger the dragleave event; if the element is put into the target element, the drop event instead of the dragleave event will be triggered)

3. Custom target Element

Although all elements support the placement of target events, these elements are not allowed by default. If you drag an element that is not allowed to be placed, no matter how Yonghui operates, the drop event is triggered.

To allow placement, We must block the default Processing Method for elements:

You must call the event of the dragover event. the preventDefault () method is used to prevent default events, that is, the attribute cannot be placed when the target element is changed. When the element is released by the mouse on the target element, the drop event is triggered.


Related Article

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.