Use native JavaScript For a drag effect

Source: Internet
Author: User

The Drag status is x: 0, y: 0 Drag me.Any directionHorizontal DirectionVerticalStop draggingEnable dragRestore initial status

Basic drag:

New Dragdrop ({target drag element HTMLElemnt required bridge: Specifies the drag start when the mouse is pressed, whether dragable can be dragged in the modal dialog box (true) default dragX true/false horizontal direction cannot be dragged (true) default dragY true/false vertical direction cannot be dragged (true) default area [minX, maxX, minY, maxY] specifies the drag range. By default, the callback function is used when callback is dragged });

The most technical content of drag and drop is this section:

If (el. setCapture) {// IEE. on (el, "losecapture", mouseup); el. setCapture (); e. cancelBubble = true;} else if (window. captureEvents) {// standard DOMe. stopPropagation (); E. on (window, "blur", mouseup); e. preventDefault ();}

This effect is not implemented using JQuery, pure native JavaScript. For details, refer. The drag effect is smooth, natural, and the CPU performance is not significantly fluctuating.

You can view the source code on this page after dragging it.

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.