<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
#d1{
width:1000px;
height:1000px;
background-color: aqua;
position: absolute;
cursor: move;
}
</style>
</head>
<body>
<div id="d1"></div>
<script type="text/javascript">
var d1Node = document.getElementById("d1");
d1Node.onmousedown = function(e){
var w =e.clientX - d1Node.offsetLeft;
var h =e.clientY - d1Node.offsetTop;
document.onmousemove = function(ev){
d1Node.style.top = (ev.clientY - h) + "px";
d1Node.style.left = (ev.clientX - w) + "px";
}
}
d1Node.onmouseup = function(){
document.onmousemove = null;
}
</script>
</body>
</html>
移动的div
最新推荐文章于 2024-07-26 11:41:15 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)