日期:2014-05-20  浏览次数:20810 次

求高手js的问题
这段代码用来实现图片在页面上下左右飘动的,,在IE里可以四处飘动,但火狐和360就只是靠在上面左右移动
HTML code
<script type="text/javascript">
            //js漂浮窗口
                var Rimifon = { 
            "Ads" : new Object, 
            "NewFloatAd" : function(imgUrl, strLink) 
            { 
            var ad = document.createElement("a"); 
            ad.DirV = true; 
            ad.DirH = true; 
            ad.AutoMove = true; 
            ad.Image = new Image; 
            ad.Seed = 15; 
            ad.Timer = setInterval("Rimifon.Float(" + ad.Seed + ")", 30); 
            this.Ads[ad.Seed] = ad; 
            ad.Image.Parent = ad; 
            ad.style.position = "absolute"; 
            ad.style.left = 0; 
            ad.style.top = 0; 
            ad.Image.src = imgUrl; 
            ad.Image.onmouseover = function(){this.Parent.AutoMove = false;} 
            ad.Image.onmouseout = function(){this.Parent.AutoMove = true;} 
            if(strLink) 
            { 
            ad.href = strLink; 
            ad.Image.border = 0; 
            ad.target = "_blank"; 
            } 
            ad.appendChild(ad.Image); 
            document.body.appendChild(ad); 
            return ad; 
            }, 
            "Float" : function(floatId) 
            { 
            var ad = this.Ads[floatId]; 
            if(ad.AutoMove) 
            { 
            var curLeft = parseInt(ad.style.left); 
            var curTop = parseInt(ad.style.top); 
            if(ad.offsetWidth + curLeft > document.body.clientWidth + document.body.scrollLeft - 1) 
            { 
            curLeft = document.body.scrollLeft + document.body.clientWidth - ad.offsetWidth; 
            ad.DirH = false; 
            } 
            if(ad.offsetHeight + curTop > document.body.clientHeight + document.body.scrollTop - 1) 
            { 
            curTop = document.body.scrollTop + document.body.clientHeight - ad.offsetHeight; 
            ad.DirV = false; 
            } 
            if(curLeft < document.body.scrollLeft) 
            { 
            curLeft = document.body.scrollLeft; 
            ad.DirH = true; 
            } 
            if(curTop < document.body.scrollTop) 
            { 
            curTop = document.body.scrollTop; 
            ad.DirV = true; 
            } 
            ad.style.left = curLeft + (ad.DirH ? 1 : -1) + "px"; 
            ad.style.top = curTop + (ad.DirV ? 1 : -1) + "px"; 
            } 
            } 
            }
</script>



------解决方案--------------------
从这里开始
var curLeft = parseInt(ad.style.left); 
var curTop = parseInt(ad.style.top); 
if(ad.offsetWidth + curLeft > document.body.clientWidth + document.body.scrollLeft - 1) 

curLeft = document.body.scrollLeft + document.body.clientWidth - ad.offsetWidth; 
ad.DirH = false; 

if(ad.offsetHeight + curTop > document.body.clientHeight + document.body.scrollTop - 1) 

curTop = document.body.scrollTop + document.body.clientHeight - ad.offsetHeight; 
ad.DirV = false; 

if(curLeft < document.body.scrollLeft) 

curLeft = document.body.scrollLeft; 
ad.DirH = true; 
}