<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.w{
position: absolute;margin: auto;left: 20%;top: 35%;
}
.t{
width: 160px;
height: 220px;
background-color: pink;
position: fixed;top: 20px;
}
.b{
width: 180px;
height: 80px;
background-color: #7FFFD4;
}
</style>
</head>
<body>
<div>
<div class="w">
<div class="t" id="t" ></div>
<div class="b"></div>
</div>
</div>
<script type="text/javascript">
var t = document.getElementById('t')
var boxC,mouseC;
t.onmousedown = function () {
boxC = t.style.top
mouseC = event.clientY
t.onmousemove = function(){
// t.style.top = event.clientY - 100 + 'px'
t.style.top = boxC + (event.clientY - mouseC) + 'px'
}
}
t.onmouseup = function(){
t.onmousemove = null
}
</script>
</body>
</html>
前端小白,想写一个拖拽效果,但是拖拽一次后就无法再拖拽