[阅读: 720] 2006-09-07 08:14:48
<html>
<head>
<title>DIV</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</head>
<body>
<div onmousedown="dragStart(this)" style="position:absolute;left:300;top:200;width:200;height:100;background-color:#FFFFEE;border:1px solid black">
I'm moving....
</div>
<script language="JavaScript">
function dragStart(obj){
obj.deltaX = event.clientX - obj.offsetLeft;
obj.deltaY = event.clientY - obj.offsetTop;
obj.onmousemove = new Function("dragMove(this)");
obj.onmouseup = new Function("dragDone(this)");
obj.setCapture();
}
function dragMove(obj){
obj.style.left = event.clientX - obj.deltaX;
obj.style.top = event.clientY - obj.deltaY;
}
function dragDone(obj){
obj.onmousemove = null;
obj.onmouseup = null;
obj.releaseCapture();
}
</script>
</body>
</html>