<style>
#box1 {
width: 100px;
height: 100px;
background-color: red;
position: absolute;
}
#box2 {
width: 100px;
height: 100px;
background-color: rgb(39, 32, 32);
position: relative;
top: 30px;
left: 200px;
}
</style>
<script>
window.onload=function(){
var box1=document.getElementById("box1");
//鼠标按下
box1.onmousedown=function(event){
event=event||window.event;
//鼠标在盒子里不变位置,求鼠标相对于盒子的相对偏移量
var ol=event.clientX-box1.offsetLeft;
var ot=event.clientY-box1.offsetTop;
//获取鼠标坐标,修改box1位置
document.onmousemove=function(event){
//兼容
event=event||window.event;
JavaScript鼠标拖拽(应用场所,桌面拖拽应用软件)
最新推荐文章于 2024-02-17 09:28:20 发布