
firefox js ie 兼容问题 在chrome和ie下正常,ff下第一次正常,第二次拖动有问题。。。
<!doctypehtml><html><head><style>div{width:200px;height:200px;background:red;position...
<!doctype html>
<html>
<head>
<style>
div {width:200px;height:200px;background:red;position:absolute;}
</style>
<script>
var Drag=function(obj) {
var x,y,ox,oy;
var nx,ny;
var objmove=new Boolean(false);
obj.onmousedown=function(e) {
e=e||event;
if(e.button==0) {
obj.style.cursor="move";
ox=obj.offsetLeft;
oy=obj.offsetTop;
x=e.clientX;
y=e.clientY;
objmove=true;
};
};
obj.onmousemove=function(e) {
e=e||event;
if(objmove==true) {
nx=ox+e.clientX-x;
ny=oy+e.clientY-y;
obj.style.left=nx+"px";
obj.style.top=ny+"px";
}
};
obj.onmouseup=function(e) {
e=e||event;
if(e.button==0) {
objmove=false;
obj.style.cursor="default";
}
};
};
window.onload=function() {
var oDiv=document.getElementsByTagName("div")[0];
Drag(oDiv);
}
</script>
</head>
<body>
<div></div>
</body>
</html> 展开
<html>
<head>
<style>
div {width:200px;height:200px;background:red;position:absolute;}
</style>
<script>
var Drag=function(obj) {
var x,y,ox,oy;
var nx,ny;
var objmove=new Boolean(false);
obj.onmousedown=function(e) {
e=e||event;
if(e.button==0) {
obj.style.cursor="move";
ox=obj.offsetLeft;
oy=obj.offsetTop;
x=e.clientX;
y=e.clientY;
objmove=true;
};
};
obj.onmousemove=function(e) {
e=e||event;
if(objmove==true) {
nx=ox+e.clientX-x;
ny=oy+e.clientY-y;
obj.style.left=nx+"px";
obj.style.top=ny+"px";
}
};
obj.onmouseup=function(e) {
e=e||event;
if(e.button==0) {
objmove=false;
obj.style.cursor="default";
}
};
};
window.onload=function() {
var oDiv=document.getElementsByTagName("div")[0];
Drag(oDiv);
}
</script>
</head>
<body>
<div></div>
</body>
</html> 展开
2个回答
展开全部
尊敬的用户,您好!很高兴为您答疑。
您的代码在火狐浏览器下进行了反复测试,并未发生您所说的第二次拖动无效的情况,而您的代码中捕捉的是鼠标的onmousedown事件,推测您会否是因为浏览器中安装了拖拽扩展与您的这个操作冲突所致。
希望我的回答对您有所帮助,如有疑问,欢迎继续咨询我们。
您的代码在火狐浏览器下进行了反复测试,并未发生您所说的第二次拖动无效的情况,而您的代码中捕捉的是鼠标的onmousedown事件,推测您会否是因为浏览器中安装了拖拽扩展与您的这个操作冲突所致。
希望我的回答对您有所帮助,如有疑问,欢迎继续咨询我们。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询