中国开发网: 论坛: 程序员情感CBD: 贴子 393196
有狐
我来一个DIV的Drag
<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>

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录