首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

div拖拽的事例

2013-03-25 
div拖拽的例子titletest drag/titlestyle typetext/css!--.drag {width:100pxheight:100pxpos

div拖拽的例子
<title>test drag</title>
<style type="text/css">
<!--
.drag {
width:100px;
height:100px;
position:absolute;
left:210px;
top:210px;
background-color:blue;
}
-->
</style>
<script type="text/javascript">
<!--
function drag(target,event)
{
?? var deltaX = event.clientX-parseInt(target.style.left);
?? var deltaY = event.clientY-parseInt(target.style.top);
??
?? document.attachEvent("onmousemove",movehandle);
?? document.attachEvent("onmouseup",uphandle);

?? function movehandle()
?? {
??? target.style.left = event.clientX-deltaX;
??? target.style.top = event.clientY-deltaY;
?? }

?? function uphandle()
?? {
??? document.detachEvent("onmousemove",movehandle);
??? document.detachEvent("onmouseup",uphandle);
?? }
}
-->
</script>
</head>
<body>
<br/>
<br/>
<br/>
<div id="drag1" style="left:10px;top:10px;background-color:red;"? onmousedown="drag(this,event);" >show me you 2</div>
<div id="drag" onmousedown="drag(this,event);" style="left:10px;top:10px;">show me you</div>
</body>
</html>

热点排行