下面的代码在IE中正常,但是在firefox中不能飘动!
代码如下:
<div id="ad" style="position:absolute">
<a href="yfjl/index.asp" target="_blank">
<img src="images/jlwt.png" border="0">
</a></div>
<script>
var x = 50,y = 60
var xin = true, yin = true
var step = 1
var delay = 10
var obj=document.getElementById("ad")
function floatAD() {
var L=T=0
var R= document.body.clientWidth-obj.offsetWidth
var B = document.body.clientHeight-obj.offsetHeight
obj.style.left = x + document.body.scrollLeft
obj.style.top = y + document.body.scrollTop
x = x + step*(xin?1:-1)
if (x < L) { xin = true; x = L}
if (x > R){ xin = false; x = R}
y = y + step*(yin?1:-1)
if (y < T) { yin = true; y = T }
if (y > B) { yin = false; y = B }
}
var itl= setInterval("floatAD()", delay)
obj.onmouseover=function(){clearInterval(itl)}
obj.onmouseout=function(){itl=setInterval("floatAD()", delay)}
</script>请高手指点 

解决方案 »

  1.   

    页面顶部加上:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">然后把所有document.body换成document.documentElement
    再然后:obj.style.left = x + document.body.scrollLeft +"px"
      

  2.   

    一般说来,ff的兼容性高,竟然有IE可以,FF不行的情况,长见识,呼呼。
      

  3.   

    sohighthesky,我按照你的方法做了,还是不行,在ff中不飘动
      

  4.   

    以下代码:
    ie8,ff3.5,chrome3.0下测试通过<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head><title></title></head>
    <body>
    <div id="ad" style="position:absolute"> 
    <a href="yfjl/index.asp" target="_blank"> 
    <img src="http://avatar.profile.csdn.net/6/D/1/2_sohighthesky.jpg" border="0"> 
    </a> </div> 
    </body>
    <script> 
    var x = 50,y = 60 
    var xin = true, yin = true 
    var step = 1 
    var delay =10
    var obj=document.getElementById("ad") 
    function floatAD() { 
    var L=T=0 
    var de=document.documentElement;
    var R= de.clientWidth-obj.offsetWidth 
    var B = de.clientHeight-obj.offsetHeight 
    obj.style.left = x + de.scrollLeft +'px';
    obj.style.top = y + de.scrollTop +'px';
    document.title=obj.style.left +"|" +obj.style.top;
    x = x + step*(xin?1:-1) 
    if (x < L) { xin = true; x = L} 
    if (x > R){ xin = false; x = R} 
    y = y + step*(yin?1:-1) 
    if (y < T) { yin = true; y = T } 
    if (y > B) { yin = false; y = B } 

    var itl= setInterval("floatAD()", delay) 
    obj.onmouseover=function(){clearInterval(itl)} 
    obj.onmouseout=function(){itl=setInterval("floatAD()", delay)} 
    </script> 
    </html>
      

  5.   

    1楼的方法是正确的 我刚遇到这样的问题, 在w3c标准中 document.body.clientWidth 是没用的。 
    $(document).ready(function(){
        //隐藏错误提示的方法
        $("#btnKnow").click(function(){
            $("#message").text("");
            $("#divShowError").hide();
        });
        picTop = (document.documentElement.clientHeight - 112) / 2
        $("#divShowError").css("top", picTop);
        $("#divShowError").css("left", (document.documentElement.clientWidth - 350) / 2);
    });
    这样的话 在w3c标准中就没问题了。