JQuery element drag-and-drop prototype code

Source: Internet
Author: User

This article mainly analyzes the drag-and-drop prototype and provides a simple example for fans who are new to JQuery.
After Jquery. js is introduced:
Copy codeThe Code is as follows:
<Script type = "text/javascript">
$ (Function (){
// Bind the drag Element Object
BindDrag (document. getElementById ('test '));
});
Function bindDrag (el ){
// Initialization parameters
Var els = el. style,
// Coordinates of the X and Y axes of the mouse
X = y = 0;
// Evil index finger
$ (El). mousedown (function (e ){
// Press the element to calculate the current mouse position
X = e. clientX-el. offsetLeft;
Y = e. clientY-el. offsetTop;
// Capture the focus in IE
El. setCapture & el. setCapture ();
// Bind events
$ (Document). bind ('mousemove ', mousemove). bind ('mouseup', mouseup );
});
// Move the event
Function mouseMove (e ){
// Super invincible universe computing...
Els. top = e. clientY-y + 'px ';
Els. left = e. clientX-x + 'px ';
}
// Stop the event
Function mouseUp (){
// Release the focus in IE
El. releaseCapture & el. releaseCapture ();
// Uninstall the event
$ (Document). unbind ('mousemove ', mousemove). unbind ('mouseup', mouseup );
}
}
</Script>

Download: complete example

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.