JQuery drag-and-drop plug-in implementation code _ jquery

Source: Internet
Author: User
For a long time, I have been very confused about the position of elements obtained by JS: client, offset, and scroll. In addition, the incompatibility between various browsers makes it dizzy. Many page effects require these locations. You have to practice and remember.
Let's talk about this simple JQuery-based drag-and-drop plug-in.
By convention, let's first talk about the drag and drop principle and the steps for doing this stuff:
What is drag? You can see the name: drag a stuff. Put it on our DOM to change its position.
It has only two difficulties: 1. How do you know it is dragging? 2. How do I know where to drag and drag?
In fact, this is not difficult. After all, both are basic things, and the key is proficiency.
To switch to js, let's make a drag effect. The steps are as follows:
1. Let elements capture events (generally, they are nothing more than mousedown, mousemove, and mouseup)
2. When mousedown, Mark start dragging and obtain the element and mouse position.
3. During mousemove, You can constantly obtain the new location of the mouse and use the corresponding location algorithm to locate the element position again.
4. When mouseup is enabled, stop dragging... And then start again.
In the middle of this section, you must note that the elements to be dragged must at least be relatively or absolutely located; otherwise, the drag operation will not work.
OK. I don't know much about it. There is no code or truth. The corresponding explanations are as follows:
Download:

The Code is as follows:






Jeremy-DragDrop Test!

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.