Native js achieves the drag-and-drop login box effect, and js-drag Login

Source: Internet
Author: User

Native js achieves the drag-and-drop login box effect, and js-drag Login

Implementation Principle

1. When the onmousemove event is triggered, the cursor pageXY is constantly updated to change the position,

Offset of the login box = current cursor position-distance from the mouse to the border of the login box

2. When the onmousedown mouse is pressed, the trigger event gets the distance from the mouse to the login box, and then sets true to allow drag

3. onmouseup

4. Formula for displaying the logon box in the center: (visible area width and height-Logon area width and height)/2

5. When the browser window size changes, the event window. onresize is triggered, and the center of the logon box is updated.

Detailed comments in the code

Complete code

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

The above is all the content of this article. I hope this article will help you in your study or work. I also hope to provide more support to the customer's home!

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.