Compatible with the simple drag-and-drop drag of mainstream browsers

Source: Internet
Author: User


<! Doctype HTML public "-// W3C // dtd xhtml 1.0 strict // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> untitled document </title>

<Style type = 'text/CSS '>
# D {border: 1px solid green; width: 90px; Height: 57px; position: absolute ;}
# H {border: 1px solid green; width: 90px; Height: 17px; position: absolute ;}
</Style>
<SCRIPT type = 'text/JavaScript 'src = "/JS/jquery/jquery-1.2.6.min.js"> </SCRIPT>
<SCRIPT type = 'text/JavaScript '>
(Function ($ ){
$. FN. Extend ({
Drag: function (ID ){
$ (This). mousedown (function (event ){
VaR OBJ, PX, Py;
Document. onmouseup = MUP;
Document. onmousemove = mmove;
Mdown (ID, event );
Function mdown (ID, event ){
OBJ = Document. getelementbyid (ID );
If (obj. setcapture)
OBJ. setcapture ();
Else
Window. captureevents (event. mousemove | event. mouseup );
Px = event. clientx-obj. offsetleft;
Py = event. clienty-obj. offsettop;
}
Function mmove (event ){
If (window. Event) event = Window. event;
If (OBJ ){
OBJ. style. Left = event. clientx-px + "PX ";
OBJ. style. Top = event. clienty-py + "PX ";
}
}
Function MUP (event ){
If (OBJ ){
If (obj. releasecapture)
OBJ. releasecapture ();
Else
Window. captureevents (event. mousemove | event. mouseup );
OBJ = NULL;
}
}
});
}
});
}) (Jquery );

</SCRIPT>
</Head>
<Body>
<Div id = "D">
<Div id = "H"> header </div>
</Div>

<SCRIPT type = 'text/JavaScript '>
$ ("# H"). Drag ('D'); // under IE, click id = 'H' to drag id = 'D', FF compatibility to be improved
</SCRIPT>
</Body>
</Html>

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.