firefox下图片拖动的问题

  Firefox下拖动图片时,如果onmousedown函数未return false,document.onmousemove事件不响应,反而mouseup后响应document.onmousemove事件,晕掉~~

  return false后,Firefox下的obj.captureEvent和ie下的obj.setCapture有很大区别,所以设不设置captureEvent都没什么区别,当拖拽出document范围外释放鼠标时,鼠标再次移动到document内,图片还是会根据鼠标移动,暂时不知道如何解决╮(╯▽╰)╭

测试代码如下
+展开
-HTML
<img src="1.jpg" style="width:300px;position:absolute;left:100;top:100px;" id="dragImg" class="cdft" />
<script type="text/javascript">
var img=document.getElementById('dragImg'),ox,oy,ex,ey,isDrag=false,isIE=!!document.all;
img.onmousedown=function(e){
   e=e||event;
   isDrag=true;
   if(isIE)img.setCapture();
   ox=parseInt(img.style.left);oy=parseFloat(img.style.top);
   ex=e.clientX;ey=e.clientY;
   return false;//注意这里要return false,要不Firefox下拖拽不了。
}
document.onmousemove=function(e){
  e=e||event;
  if(isDrag===true){
    img.style.left=ox+e.clientX-ex+'px';
    img.style.top=oy+e.clientY-ey+'px';
  }
}
document.onmouseup=function(){
  if(isIE)img.releaseCapture();
  isDrag=false;
}
</script> 

加支付宝好友偷能量挖...


原创文章,转载请注明出处:firefox下图片拖动的问题

评论(0)Web开发网
阅读(137)喜欢(0)HTML/CSS兼容/XML