Create a drag object when mousedown, and release the object when mouseup. The principle is very simple.
Simple drag implementation code:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Strict // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <ptml xmlns = "http://www.w3.org/1999/xhtml"> <pead> <meta http-equiv =" content-Type "content =" text/html; charset = UTF-8 "/> <title> simple drag implementation </title> <style type =" text/css "> * {margin: 0; padding: 0 ;} # box {margin: 20px auto; position: relative; width: 400px; height: 400px; background: # ccc; border: 1px solid #333; postion: relative ;} # dragBox {width: 50px; height: 50px; text-align: center; line-height: 50px; position: absolute; background: blue; cursor: move; font-size: 12px; color: # fff ;}</style> </pead> <body> drag me </body> </ptml>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]