为什么在个鼠标拖拽事件实现不了?只能点击哪里图像移动到哪里
X,Y获取的数据为什么不是鼠标松开时而是鼠标按下的?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>移动图片</title>
<style>
body{
background: red;
}
.box{
width: 600px;
height: 400px;
position: relative;
background: black;
top: 100px;
left:200px;
}
img{
width: 100px;
height: 100px;
position: absolute;
top: 0;
left: 0;
}
</style>
</head>
<body>
<div class="box" id="bbox">
<img src="images\js.png" alt="" id="jss">
</div>
<script type="text/javascript" src="js\jquery-2.1.3.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var isDown = false;
$("#bbox").mousedown(function () {
isDown = true;
});
$("#bbox").mouseup(function () {
if(isDown = true){
x = event.offsetX+"px";
y = event.offsetY+"px";
}
$("#jss").css({"left":x,"top":y});
isDown = false;
});
});
</script>
</body>
</html>