• [ x0429.COM 电 脑 知 识 学 习 网 ]
  • RSS订阅
  • 网站地图
  • 搜索: 您的位置电脑基础知识网>网站素材>阅读资讯文章

    网页中加入下雨的效果背景特效

    2008-05-19 10:16:08 来源:网络其他网站 作者:采集 点击: 评论:0
    %26lt;script language=%26quot;JavaScript%26quot;%26gt;
    %26lt;!--
    var no = 50;
    var speed = 1;
    var ns4up = (document.layers) ? 1 : 0;
    var ie4up = (document.all) ? 1 : 0;
    var s, x, y, sn, cs;
    var a, r, cx, cy;
    var i, doc_width = 800, doc_height = 600;
    if (ns4up) {
    doc_width = self.innerWidth;
    doc_height = self.innerHeight;
    }
    else
    if (ie4up) {
    doc_width = document.body.clientWidth;
    doc_height = document.body.clientHeight;
    }
    x = new Array();
    y = new Array();
    r = new Array();
    cx = new Array();
    cy = new Array();
    s = 8;
    for (i = 0; i %26lt; no; ++ i) {
    initRain();
    if (ns4up) {
    if (i == 0) {
    document.write(%26quot;%26lt;layer name=%26quot;dot%26quot;+ i +%26quot;%26quot; left=%26quot;1%26quot; %26quot;);
    document.write(%26quot;top=%26quot;1%26quot; visibility=%26quot;show%26quot;%26gt;%26lt;font color=%26quot;#999999%26quot;%26gt;%26quot;);
    document.write(%26quot;,%26lt;/font%26gt;%26lt;/layer%26gt;%26quot;);
    }
    else {
    document.write(%26quot;%26lt;layer name=%26quot;dot%26quot;+ i +%26quot;%26quot; left=%26quot;1%26quot; %26quot;);
    document.write(%26quot;top=%26quot;1%26quot; visibility=%26quot;show%26quot;%26gt;%26lt;font color=%26quot;#999999%26quot;%26gt;%26quot;);
    document.write(%26quot;,%26lt;/font%26gt;%26lt;/layer%26gt;%26quot;);
    }
    }
    else
    if (ie4up) {
    if (i == 0) {
    document.write(%26quot;%26lt;div id=%26quot;dot%26quot;+ i +%26quot;%26quot; style=%26quot;POSITION: %26quot;);
    document.write(%26quot;absolute; Z-INDEX: %26quot;+ i +%26quot;; VISIBILITY: %26quot;);
    document.write(%26quot;visible; TOP: 15px; LEFT: 15px;%26quot;%26gt;%26lt;font color=%26quot;#999999%26quot;%26gt;%26quot;);
    document.write(%26quot;,%26lt;/font%26gt;%26lt;/div%26gt;%26quot;);
    }
    else {
    document.write(%26quot;%26lt;div id=%26quot;dot%26quot;+ i +%26quot;%26quot; style=%26quot;POSITION: %26quot;);
    document.write(%26quot;absolute; Z-INDEX: %26quot;+ i +%26quot;; VISIBILITY: %26quot;);
    document.write(%26quot;visible; TOP: 15px; LEFT: 15px;%26quot;%26gt;%26lt;font color=%26quot;#999999%26quot;%26gt;%26quot;);
    document.write(%26quot;,%26lt;/font%26gt;%26lt;/div%26gt;%26quot;);
    }
    }
    }
    function initRain() {
    a = 6;
    r[i] = 1;
    sn = Math.sin(a);
    cs = Math.cos(a);
    cx[i] = Math.random() * doc_width + 1;
    cy[i] = Math.random() * doc_height + 1;
    x[i] = r[i] * sn + cx[i];
    y[i] = cy[i];
    }
    function makeRain() {
    r[i] = 1;
    cx[i] = Math.random() * doc_width + 1;
    cy[i] = 1;
    x[i] = r[i] * sn + cx[i];
    y[i] = r[i] * cs + cy[i];
    }
    function updateRain() {
    r[i] += s;
    x[i] = r[i] * sn + cx[i];
    y[i] = r[i] * cs + cy[i];
    }
    function raindropNS() {
    for (i = 0; i %26lt; no; ++ i) {
    updateRain();
    if ((x[i] %26lt;= 1) || (x[i] %26gt;= (doc_width - 20)) || (y[i] %26gt;= (doc_height - 20))) {
    makeRain();
    doc_width = self.innerWidth;
    doc_height = self.innerHeight;
    }
    document.layers[%26quot;dot%26quot;+i].top = y[i];
    document.layers[%26quot;dot%26quot;+i].left = x[i];
    }
    setTimeout(%26quot;raindropNS()%26quot;, speed);
    }
    function raindropIE() {
    for (i = 0; i %26lt; no; ++ i) {
    updateRain();
    if ((x[i] %26lt;= 1) || (x[i] %26gt;= (doc_width - 20)) || (y[i] %26gt;= (doc_height - 20))) {
    makeRain();
    doc_width = document.body.clientWidth;
    doc_height = document.body.clientHeight;
    }
    document.all[%26quot;dot%26quot;+i].style.pixelTop = y[i];
    document.a

    ll[%26quot;dot%26quot;+i].style.pixelLeft = x[i];
    }
    setTimeout(%26quot;raindropIE()%26quot;, speed);
    }
    if (ns4up) {
    raindropNS();
    }
    else
    if (ie4up) {
    raindropIE();
    }

    --%26gt;
    %26lt;/script%26gt;



    Tags:[标签:标签]  
    责任编辑:
  • 请文明参与讨论,禁止漫骂攻击。 用户名:新注册) 密码: 匿名:
    评论总数:0 [ 查看全部 ] 网友评论