Drag a program (HTML + CSS + JavaScript)

Source: Internet
Author: User

DragProgram
Principle: Move the dragged element based on the movement of the mouse. The movement of the mouse is the change of the X and Y coordinates. The movement of the element is the change of the top and left of the style. position. First, you must determine whether to press the mouse or not on the corresponding drag-and-drop element.

Basic Ideas:
Record the drag status (0: not pressed; 1: pressed)
Press {
Status = 1;
Record element x and y values
Record mouse x and y values
}

When moving {
Judge whether the status is 1
If it is 1, then:
Element x = current mouse X-original mouse x + original element x:
Element y = current mouse y-original mouse y + Element Original Y:
}

When releasing {
Status = 0;
Determine whether the database is in the specified range:
Automatic Location Adjustment;
}

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.