JS技术

javascript拖动小例子_javascript教程教程

字号+ 作者:H5之家 来源:H5之家 2015-10-03 13:02 我要评论( )

html head meta http-equiv="Content" content="text/html;chartset=utf-8" titletest drag/title style type="text/css" !-- .drag { width:100px; height:100px; position:absolute; left:10px; top:10px; background-color:blue; } -- /style script type

<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  onmousedown="drag(this,event);" >show me you 2</div>
<div onmousedown="drag(this,event);">show me you</div>

</body>
</html>

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • javascript拖动小例子

    javascript拖动小例子

    2014-11-17 20:00

网友点评