Javascript拖动DIV层

Javascript拖动DIV层代码如下:

<html>
<body>
<style>
body{font-family:Verdana;font-size:11px;color:#333;}
#win1{[position:absolute;left:100;top:100;200px;height:150px;border:1px solid #000;}
.title{100%;background:#000;height:18px;color:#fff;cursor: move;}
</style>

<script>
var move=false;
var intX;
var intY;
function StartDrag(obj)
{
if(event.button==1&&event.srcElement.tagName.toUpperCase()=="DIV")
{
obj.setCapture();
obj.style.background="#999";
intX = event.clientX - obj.style.pixelLeft;
intY = event.clientY - obj.style.pixelTop;
move=true;
}
}

function Drag(obj)
{
if(move)
{
var oldwin=obj.parentNode;
oldwin.style.left=event.clientX-intX;
oldwin.style.top=event.clientY-intY;
}

}

function StopDrag(obj)
{
obj.style.background="#000";
obj.releaseCapture();
move=false;
}

</script>

<div id="win1">
<div class="title" onMousedown="StartDrag(this)" onMouseup="StopDrag(this)" onMousemove="Drag(this)" >窗口1</div>
设计家园<br>
www.dwww.cn .
</div>

</body>
</html>

原文地址:https://www.cnblogs.com/citygs/p/1859968.html