叶子谷- 网页教程

RSS订阅 站长资讯通告:
搜索: 您现在的位置: 叶子谷 >> 网页特效 >> 页面特效 >> 正文

向上飘动的水泡

2008-06-10 13:50:46 来源:网络 作者:佚名 【 点击:
将下面的代码加在body之间:


<script language="JavaScript1.2">
<!-- Begin
var no = 15; // images number or falling rate
var speed = 2; // the lower the number the faster the image moves
var snow = new Array();
snow[0] = "bubble.gif"
snow[1] = "bubble.gif"
snow[2] = "bubble.gif"
var ns4up = (document.layers) ? 1 : 0;  // browser sniffer
var ie4up = (document.all) ? 1 : 0;
var ns6up = (document.getElementById&&!document.all) ? 1 : 0;
var dx, xp, yp;    // coordinate and position variables
var am, stx, sty;  // amplitude and step variables
var I, doc_width = 800, doc_height = 1800;
if (ns4up||ns6up) {
        doc_width = self.innerWidth;
        doc_height = self.innerHeight;
} else if (ie4up) {
        doc_width = document.body.clientWidth;
        doc_height = document.body.clientHeight;
}
dx = new Array();
xp = new Array();
yp = new Array();
am = new Array();
stx = new Array();
sty = new Array();
j = 0;
for (I = 0; I < no; ++ I) {
        dx[I] = 0;                        // set coordinate variables
        xp[I] = Math.random()*(doc_width-50);  // set position variables
        yp[I] = Math.random()*doc_height;
        am[I] = Math.random()*20;        // set amplitude variables
        stx[I] = 0.02 + Math.random()/10; // set step variables
        sty[I] = 0.7 + Math.random();    // set step variables
        if (ns4up) {                      // set layers
                if (I == 0) {
                        document.write("<layer name=\"dot"+ I +"\" left=\"15\" top=\"15\" visibility=\"show\"><img src=\""+ snow[j] + "\" border=\"0\"></layer>");
                } else {
                        document.write("<layer name=\"dot"+ I +"\" left=\"15\" top=\"15\" visibility=\"show\"><img src=\""+ snow[j] + "\" border=\"0\"></layer>");
                }        } else if (ie4up||ns6up) {                if (I == 0)
{
                        document.write("<div id=\"dot"+ I +"\" style=\"POSITION: absolute; Z-INDEX: "+ I +"VISIBILITY: visible; TOP: 15px; LEFT: 15px; width:1;\"><img src=\"" + snow[j] + "\" border=\"0\"></div>");
                } else {
                        document.write("<div id=\"dot"+ I +"\" style=\"POSITION: absolute; Z-INDEX: "+ I +"VISIBILITY: visible; TOP: 15px; LEFT: 15px; width:1;\"><img src=\"" + snow[j] + "\" border=\"0\"></div>");
                }
        }
        if (j == (snow.length-1)) { j = 0; } else { j += 1; }
}
function snowNS() {  // Netscape main animation function
        for (I = 0; I < no; ++ I) {  // iterate for every dot
                yp[I] -= sty[I];                if (yp[I] < -50) {
                        xp[I] = Math.random()*(doc_width-am[I]-30);
                        yp[I] = doc_height;
                        stx[I] = 0.02 + Math.random()/10;
                        sty[I] = 0.7 + Math.random();
                        doc_width = self.innerWidth;
                        doc_height = self.innerHeight;                }
                dx[I] += stx[I];
                document.layers["dot"+I].top = yp[I]+pageYOffset;
                document.layers["dot"+I].left = xp[I] +
am[I]*Math.sin(dx[I]);
        }
        setTimeout("snowNS()", speed);
}
function snowIE_NS6() {  // IE main animation function
        for (I = 0; I < no; ++ I) {  // iterate for every dot
                yp[I] -= sty[I];
                if (yp[I] < -50) {
                        xp[I] = Math.random()*(doc_width-am[I]-30);
                        yp[I] = doc_height;
                        stx[I] = 0.02 + Math.random()/10;
                        sty[I] = 0.7 + Math.random();
                        doc_width = ns6up?window.innerWidth-5:document.body.clientWidth;
                        doc_height = ns6up?window.innerHeight-5:document.body.clientHeight;
                }
                dx[I] += stx[I];
                if (ie4up){
                document.all["dot"+I].style.pixelTop = yp[I]+document.body.scrollTop;
                document.all["dot"+I].style.pixelLeft = xp[I] + am[I]*Math.sin(dx[I]);
                }
                else if (ns6up){
                document.getElementById("dot"+I).style.top=yp[I]+pageYOffset;
                document.getElementById("dot"+I).style.left=xp[I] + am[I]*Math.sin(dx[I]);
                }
        }
        setTimeout("snowIE_NS6()", speed);
}
if (ns4up) {
        snowNS();
} else if (ie4up||ns6up) {
        snowIE_NS6();
}
// End -->
                </script>
Tags: 网页特效  
责任编辑:cptedu
  • 发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】   
  • 上一篇文章:
  • 下一篇文章:
  • 姓 名: * Oicq:
    评 分: 1分 2分 3分 4分 5分
    评论内容:
    广告也精采
    热门文章
    设为首页 -加入收藏 - 联系我们 - 友情链接 - 版权声明 - 管理登陆