日期:2014-05-17  浏览次数:20459 次

再一次非常纠结
<script>
var moving = 0;
var _x, _y;  
function down(){  
moving = 1;  
_x = event.clientX;  
_y = event.clientY;  
}
function up(){  
ReleaseCapture();
moving = 0;  
}
function move(obj){  
if (moving == 1) {  
var x = event.clientX;  
var y = event.clientY;  
var X0 = parseInt(obj.style.marginTop);  
var Y0 = parseInt(obj.style.marginLeft);  
obj.style.marginTop = (Y0 + y-_y) + "px";
obj.style.marginLeft = (Y0 + x-_x) + "px";  

}  
}
</script>

  <div name="pa" class="par" onmousedown="down()" onmouseup="up()" onmousemove="move(this)">
  <div class="lw">  
  阿朵所发生的发生地方
  </div>
  <div id="us">匿名留</div>
  </div>
  <div name="pa" class="par" onmousedown="down()" onmouseup="up()" onmousemove="move(this)">
  <div class="lw">  
  as的发生的发生地方
  </div>
  <div id="us">匿名留</div>
  </div>

大哥们,我想做鼠标拖动移动DIV,不知哪里有问题啊,mousedown一下啊,DIV就乱飞了

------解决方案--------------------
你在JS代码里面都不判断一次鼠标是否按下了就直接移动当然就出问题了,你需要在每一个函数里面判断鼠标的状态才执行相应的代码