14方块的随便移动
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>正方体14</title>
<style>
*{
margin: 0;
padding: 0;
}
body{
position: absolute;
top: 0;
width: 100%;
}
#box{
width: 200px;
height: 200px;
background-color: aqua;
position: absolute;
top: 100px;
left: 200px;
}
</style>
</head>
<body>
<div id="box">
</div>
<script>
var box=document.getElementById("box");
var flag=0;
var offx,offy;
box.onmousedown=function(e){
flag=1;
var boxrect=box.getBoundingClientRect();
offx=e.x - boxrect.left;
offy=e.y - boxrect.top;
}
box.onmousemove=function(e){
if(flag==0) return;
box.style.left=(e.x - offx)+"px";
box.style.top=(e.y - offy)+"px";
};
</script>
</body>
</html>
白大褂&小孙

浙公网安备 33010602011771号