
Js拖动层兼容问题
varObj=''document.onmouseup=MUpdocument.onmousemove=MMovefunctionMDown(Object){Obj=Ob...
var Obj=''
document.onmouseup=MUp
document.onmousemove=MMove
function MDown(Object){
Obj=Object.id
document.all(Obj).setCapture()
pX=event.x-document.all(Obj).style.pixelLeft;
pY=event.y-document.all(Obj).style.pixelTop;
}
function MMove(){
if(Obj!=''){
document.all(Obj).style.left=event.x-pX;
document.all(Obj).style.top=event.y-pY;
}
}
function MUp(){
if(Obj!=''){
document.all(Obj).releaseCapture();
Obj='';
}
} 这是一个鼠标拖动Div层的js脚本(参数object是要拖动div的ID的形参)。怎么样修改可以让这个在FireFox上兼容?
不能用其它脚本,在这个基础上作修改,谢谢哦,成功测试无误后,追加100悬赏! 展开
document.onmouseup=MUp
document.onmousemove=MMove
function MDown(Object){
Obj=Object.id
document.all(Obj).setCapture()
pX=event.x-document.all(Obj).style.pixelLeft;
pY=event.y-document.all(Obj).style.pixelTop;
}
function MMove(){
if(Obj!=''){
document.all(Obj).style.left=event.x-pX;
document.all(Obj).style.top=event.y-pY;
}
}
function MUp(){
if(Obj!=''){
document.all(Obj).releaseCapture();
Obj='';
}
} 这是一个鼠标拖动Div层的js脚本(参数object是要拖动div的ID的形参)。怎么样修改可以让这个在FireFox上兼容?
不能用其它脚本,在这个基础上作修改,谢谢哦,成功测试无误后,追加100悬赏! 展开
1个回答
2013-09-18
展开全部
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title></title>
<style>
.move {height: 200px; position: relative; width: 300px;}
.move div {border: 1px solid #ccc; height: 100%; position: absolute; width: 100%;}
.left {float: left;}
.clear {float: none; clear: both;}
</style>
</head>
<body>
<script type="text/javascript">
var Obj;
document.onmouseup=MUp;
document.onmousemove=MMove;
document.onmousedown=MDown;
function MDown(event) {
if (window.event) {/*IE*/
event = window.event;
Obj = event.srcElement;
Obj.setCapture();
}
else {/*Firefox*/
Obj = event.target;
window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
}
pX=event.clientX-Obj.offsetLeft;
pY=event.clientY-Obj.offsetTop;
}
function MMove(event) {
if (window.event) event = window.event;
if(Obj){
Obj.style.left=event.clientX-pX + "px";
Obj.style.top=event.clientY-pY + "px";
}
}
function MUp(event) {
if(Obj){
if (window.event) Obj.releaseCapture();
else window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
Obj=null;
}
}
</script>
</body>
<div class="move left">
<div>qwert</div>
</div>
<div class="move left">
<div>yuiop</div>
</div>
<div class="clear"></div>
<div class="move left">
<div>asdf</div>
</div>
<div class="move left">
<div>ghjkl</div>
</div>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title></title>
<style>
.move {height: 200px; position: relative; width: 300px;}
.move div {border: 1px solid #ccc; height: 100%; position: absolute; width: 100%;}
.left {float: left;}
.clear {float: none; clear: both;}
</style>
</head>
<body>
<script type="text/javascript">
var Obj;
document.onmouseup=MUp;
document.onmousemove=MMove;
document.onmousedown=MDown;
function MDown(event) {
if (window.event) {/*IE*/
event = window.event;
Obj = event.srcElement;
Obj.setCapture();
}
else {/*Firefox*/
Obj = event.target;
window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
}
pX=event.clientX-Obj.offsetLeft;
pY=event.clientY-Obj.offsetTop;
}
function MMove(event) {
if (window.event) event = window.event;
if(Obj){
Obj.style.left=event.clientX-pX + "px";
Obj.style.top=event.clientY-pY + "px";
}
}
function MUp(event) {
if(Obj){
if (window.event) Obj.releaseCapture();
else window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
Obj=null;
}
}
</script>
</body>
<div class="move left">
<div>qwert</div>
</div>
<div class="move left">
<div>yuiop</div>
</div>
<div class="clear"></div>
<div class="move left">
<div>asdf</div>
</div>
<div class="move left">
<div>ghjkl</div>
</div>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?

2023-05-10 广告
您好!建议咨 深圳市微测检测有限公司,已建立起十余个专业实验室,企业通过微测检测就可以获得一站式的测试与认 证解决方案;(EMC、RF、MFi、BQB、QI、USB、安全、锂电池、快充、汽车电子EMC、汽车手机互 联、语音通话质量),认证遇...
点击进入详情页
本回答由微测检测5.10提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询