H5拖拽

<!DOCTYPE html>
<html lang="en">
<style>
#box{
width:300px;
height:150px;
background-color:purple;
position:absolute;
left:100px;
top:50px;
}
</style>
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="box" draggable="true"> </div>
<script>
const box=document.querySelector('#box');
//拖拽移动时
/* box.ondragover=function (e) {
this.style.cssText=`left:${e.clientX-100}px;top:${e.clientY-50}px`
}*/
//拖拽结束时
box.ondragend=function (e) {
this.style.cssText=`left:${e.clientX-100}px;top:${e.clientY-50}px`
}
</script>
</body>
</html>
posted @ 2019-05-30 23:04  执念、旧时光  阅读(193)  评论(0编辑  收藏  举报