WEB开发网
开发学院网页设计JavaScript javascript拖动小例子 阅读

javascript拖动小例子

 2008-10-07 20:01:19 来源:WEB开发网   
核心提示:<html><head><meta http-equiv="Content" content="text/html;chartset=utf-8"><title>test drag</title><style ty

<html>
<head>
<meta http-equiv="Content" content="text/html;chartset=utf-8">
<title>test drag</title>
<style type="text/CSS">
<!--
.drag {
width:100px;
height:100px;
position:absolute;
left:10px;
top:10px;
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>
<div id="drag1" class="drag" style="left:10px;top:10px;background-color:red;"  >show me you 2</div>
<div id="drag" class="drag" style="left:10px;top:10px;">show me you</div>

</body>
</html>

Tags:javascript 拖动 例子

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接