首页 新闻 会员 周边

急求解决!鼠标拖拽事件

0
悬赏园豆:10 [待解决问题]

为什么在个鼠标拖拽事件实现不了?只能点击哪里图像移动到哪里

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>

倾顾的主页 倾顾 | 初学一级 | 园豆:154
提问于:2015-05-15 23:04
< >
分享
所有回答(1)
0
wangYiYi | 园豆:13 (初学一级) | 2015-05-18 09:26
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册