Javascript div css drag layer

Source: Internet
Author: User
Tip: you can modify some code before running

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>Www.111cn.net drag layer</title><meta http-equiv="content-type" content="text/html;charset=gb2312"><!--把下面代码加到<head>与</head>之间--><style type="text/css">* {Padding: 0px auto; margin: 0px auto;} body {font-size: 12px; font-family: ;}. a1 {width: 135px; height: 100px; border: 1px solid red; float: left; background: lightgreen; margin: 5px; padding: 5px ;}. a2 {width: 135px; height: 100px; border: 1px solid red; float: right; background: lightgreen; margin: 5px; padding: 5px ;}</style><script language="javascript">Function tuo () {var objthis = this; this. x = null; this. y = null; this. xx = null; this. yy = null; this. xxx = null; this. yyy = null; this. obja = null; this. co = null; this. t = null; document. onmousemove = function () {try {objthis. x = arguments [0]. screenX; objthis. y = arguments [0]. screenY;} catch (err) {objthis. x = window. event. x; objthis. y = window. event. y ;}} tuo. prototype. create = function (a, B) {if (this. obja = null) {this. co = B; var objthis = this; this. obja = a; this. obja. onmouseup = function () {objthis. up ()} this. xx = this. x; this. yy = this. y; this. xxx = this. obja. offsetLeft; this. yyy = this. obja. offsetTop; this. obja. style. position = "absolute"; this. move () ;}} tuo. prototype. move = function () {var objthis = this; var x = this. xxx + this. x-this. xx; var y = this. yyy + this. y-this. yy; this. obja. style. left = x + "px"; this. obja. style. top = y + "px"; this. t = setTimeout (function () {objthis. move ()}, 1)} tuo. prototype. up = function () {clearTimeout (this. t) if (this. co = 1) {this. obja. style. left = this. xxx + "px"; this. obja. style. top = this. yyy + "px";} this. xxx = null; this. yyy = null; this. obja = null;} var PC3 = new tuo ();</script></head><body><!--把下面代码加到<body>与</body>之间--><div class="a1" onmousedown="cc1.create(this,1)">Automatically restored to the original drag layer</div><div class="a2" onmousedown="cc1.create(this)">Do not restore to the original drag layer</div></body></html>
Tip: you can modify some code before running
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.