After studying jQuery recently, I think it is really a very good js library. The key is to have a detailed document, which is very important. Of course, the Code is also very convenient to use, so you don't have to worry about a lot of things.
In the course of study, jQuery is used to implement a p drag, and the code is appended to the end of this article.
For implementation ideas, refer to my DIV (2) that can be dragged.
When referring to the examples in the jQuery Chinese website, I found that when they triggered the click event in the title bar of the p window, they moved the position of p to some of them, the mouseup event is registered in the entire p window. This idea inspired me to solve the error caused by moving the mouse fast and p cannot keep up with. It is a very good solution.
In addition, pay attention to event bubbles. In jQuery and any js Code that implements p-drag, event bubbles will undoubtedly be blocked.
In the bind or unbind method of jQuery, it is best to use false for the return value of the function. If you do not believe it, try true.
In general code, we use the stopPropagation method to prevent this event bubble process.
:
Note that the jquery-1.2.6.js is loaded
The Code is as follows: