我想停止拖动 div ,当 div 的位置在没有可拖动 ui 的特定点上时
<script type="text/javascript" src="jquery1.8.3.js"></script>
<script>
$(document).ready(function(){
var x;
var mdown = false;
$("#mydrag1").bind("mousedown",function(e){
mdown = true;
x = e.clientX;
});
$(document).bind("mousemove",function(e){
if(mdown){
var gx = e.clientX - x;
var posX = e.clientX - e.offsetX;
console.log("posX:" + posX);
if(posX < 500){//I want mydrag1's dragging is stop when mydrag1's x-position is 500
$("#mydrag1").css("left",parseInt($("#mydrag1").css("left"),10) + gx + "px");
}
x = e.clientX;
}
});
$(document).bind("mouseup",function(e){
mdown = false;
});
});
</script>
</HEAD>
<BODY>
<div id="mydrag1" style="position:absolute;left:100px;top:200px;width:200px;height:100px;background:gold">
MY DRAG1
</div>
我希望 mydrag1 的拖动是 stop ,当 mydrag1 的 x 位置为 500 但 mydrag1 仍可拖动超过 500
对不起,我的英语很差