首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

再一次十分纠结

2012-08-29 
再一次非常纠结scriptvar moving 0var _x, _yfunction down(){moving 1_x event.clientX_y

再一次非常纠结
<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代码里面都不判断一次鼠标是否按下了就直接移动当然就出问题了,你需要在每一个函数里面判断鼠标的状态才执行相应的代码

热点排行