=波波日志 > HTML/WML/CSS兼容/XML > firefox下图片拖动的问题=
firefox下图片拖动的问题
Firefox下拖动图片时,如果onmousedown函数未return false,document.onmousemove事件不响应,反而mouseup后响应document.onmousemove事件,晕掉~~
return false后,Firefox下的obj.captureEvent和ie下的obj.setCapture有很大区别,所以设不设置captureEvent都没什么区别,当拖拽出document范围外释放鼠标时,鼠标再次移动到document内,图片还是会根据鼠标移动,暂时不知道如何解决╮(╯▽╰)╭
测试代码如下
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>
<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>
类别:HTML/WML/CSS兼容/XML 作者:波波 日期:2010-05-06 【评论:0】
暂时没有评论!
发表留言
百度赞助
同类热门博文
- ·IE对CSS样式表的限制..
- ·HTML 5 WebSocket J..
- ·html5 websocket 通..
- ·Firefox上传文件获取..
- ·javascript获取file..
- ·URL转码方法及不能被..
- ·IE/Firefox/W3C浏览..
- ·CLIP: rect 是什么?
博格Tag
- flash/flex/fcs/AIR(752)
- Asp.Net/C#/WCF(598)
- 操作系统及应用软件(376)
- JavaScript/Ajax(330)
- SQL及数据库(134)
- 黑客技术(115)
- Asp/VBScript(111)
- HTML/WML/CSS兼容/XML(102)
- PHP/apache/Perl(96)
- 网站排名及优化(96)
- 其他(75)
- showbo日志(66)
- lucene.net/分词技术(33)
- 计算机网络(26)
- 机械重工(26)
- C#设计模式(25)
- Google Maps开发(17)
- 日语学习(15)
- Canvas/VML/SVG(13)
- linux(11)
- 游戏开发(8)
- 正则表达式(5)
- Jsp/Java(4)
最新博文
随机博文
