日期:2014-05-16  浏览次数:20382 次

在火狐里面打开一会就挂在右下角了 在IE下面没有问题
<body>
<div id="div1" style="position:absolute;left:0px;top:0px;width :100px;height:100px; background:blue;" >广告啊</div>



<script type="text/javascript">
 var odiv=document.getElementById("div1");
 //alert (odiv);
 var x=0;
 var y=0;
 var xs=10;
 var  ys=10;
function move (){
 x=x+xs;
 y=y+ys;
 //alert (y)
 if(x>=document.body.clientWidth-odiv.offsetWidth||x<=0)
 {
 xs=-1*xs;
 }
 
 


if (y>=document.body.clientHeight-odiv.offsetHeight||y<=0)
{
ys=-1*ys;
}

odiv.style.left=x+'px';

odiv.style.top=y+'px';

 }
 var dt =setInterval("move()",1);
odiv.onmouseover=function(){
clearInterval(dt);}
odiv.onmouseout=function(){
dt =setInterval("move()",100);
}
</script>
</body>
火狐 setinterval offsetWidht

------解决方案--------------------
引用:
<body>
<div id="div1" style="position:absolute;left:0px;top:0px;width :100px;height:100px; background:blue;" >广告啊</div>



<script type="text/javascript">
 var odiv=document.getElementById("div1");
 //alert (odiv);
 var x=0;
 var y=0;
 var xs=10;
 var  ys=10;
function move (){
 x=x+xs;
 y=y+ys;
 //alert (y)
 if(x>=document.body.clientWidth-odiv.offsetWidth
------解决方案--------------------
x<=0)
 {
 xs=-1*xs;
 }
 
 


if (y>=document.body.clientHeight-odiv.offsetHeight
------解决方案--------------------
y<=0)
{
ys=-1*ys;
}

odiv.style.left=x+'px';

odiv.style.top=y+'px';

 }
 var dt =setInterval("move()",1);
odiv.onmouseover=function(){
clearInterval(dt);}
odiv.onmouseout=function(){
dt =setInterval("move()",100);
}
</script>
</body>
在firefox中把document.body换成document.documentElement