Andy's Blog » » 可在Firefox中正常使用的浮动广告

可在Firefox中正常使用的浮动广告

<!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=gb2312" />
<meta name="author" content="Andy Tse,www.21andy.com" />
<title>浮动广告</title>
</head>

<body>
<div id="oImg" style="position: absolute; z-index: 100; top: 0; left: 0; width: 125px; height: 125px; background: #FF9900; color: #FFFFFF;">这里放浮动广告的图片</div>
<script language="javascript" type="text/javascript">
<!--
    var floatImg = document.getElementById("oImg");
    var delay = 10; //控制每次执行间隔的时间,做越大移动得越慢;
    var speed = 1; //控制每次执行移动的距离,值越大移动得越快;
    var flagX = 0;
    var flagY = 0;
    
    function toPixel(str1) {
    //该函数用于去掉数值后面的px,并将之转化为数字。
        var oldLen = str1.length;
        var newLen = oldLen - 2;
        
        str2 = str1.slice(0, newLen);
        str3 = parseInt(str2);
        
        return str3;
    }
    
    function flowImg() {
        var bWidth = document.body.clientWidth;
        var bHeight = document.body.clientHeight;
        var bLeft = document.body.scrollLeft;
        var bTop = document.body.scrollTop;
        
        var iWidth = floatImg.offsetWidth;
        var iHeight = floatImg.offsetHeight;
        var iLeft = toPixel(floatImg.style.left);
        var iTop = toPixel(floatImg.style.top);
        
        //下面一段控制横向移动
        if(iLeft < (bWidth - iWidth) && flagX == 0) {
            floatImg.style.left = (iLeft + speed) + "px";
        }
        else if(iLeft >= (bWidth - iWidth) && flagX ==0) {
            flagX = 1;
        }
        else if(iLeft > 0 && flagX == 1) {
            floatImg.style.left = (iLeft - speed) + "px";
        }
        else if(0 >= iLeft && flagX == 1) {
            flagX = 0;
        }
        
        //下面一段控制纵向移动
        if(iTop < (bHeight - iHeight) && flagY == 0) {
            floatImg.style.top = (iTop + speed) + "px";
        }
        else if(iTop >= (bHeight - iHeight) && flagY ==0) {
            flagY = 1;
        }
        else if(iTop > 0 && flagY == 1) {
            floatImg.style.top = (iTop - speed) + "px";
        }
        else if(0 >= iTop && flagY == 1) {
            flagY = 0;
        }
    }
    
    var imgInterval = setInterval("flowImg()", delay);
    floatImg.onmouseover = function() {clearInterval(imgInterval);}
    floatImg.onmouseout = function() {imgInterval = setInterval("flowImg()", delay);}
-->
</script>

<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp; </p>
</body>
</html>

Incoming search terms:

Tags:

本文地址: http://www.21andy.com/new/20060126/146.html