home *** CD-ROM | disk | FTP | other *** search
/ com!online 2002 May / comcd0502.iso / homepage / special / javascript / 01_01 / Java / Snow / snow.js < prev   
Encoding:
JavaScript  |  2000-11-12  |  3.9 KB  |  107 lines

  1.  
  2.   // This JavaScript code can be freely redistributed
  3.   // as long as this copyright notice is keept unchanged.
  4.   // This code is used on AS-IS basis and
  5.   // you use it on your own risk. Author of this code
  6.   // is not responsible for any damage that this
  7.   // code may make.
  8.   //
  9.   // If you use this JavaScript SNOW in your own web pages,
  10.   // please sent a note to snow@altan.hr.
  11.   //
  12.   // JS Snow v0.1
  13.   // finished on 11-10-1999 23:04 in Zagreb, Croatia.
  14.   //
  15.   // Copyright 1999 Altan d.o.o.
  16.   // http://www.altan.hr/
  17.   // http://www.altan.hr/snow/index.html
  18.   // E-mail: snow@altan.hr
  19.   
  20.   var no = 10; // snow number
  21.  
  22.   var ns4up = (document.layers) ? 1 : 0;  // browser sniffer
  23.   var ie4up = (document.all) ? 1 : 0;
  24.  
  25.   var dx, xp, yp;    // coordinate and position variables
  26.   var am, stx, sty;  // amplitude and step variables
  27.   var i, doc_width = 800, doc_height = 600;
  28.   
  29.   if (ns4up) {
  30.     doc_width = self.innerWidth;
  31.     doc_height = self.innerHeight;
  32.   } else if (ie4up) {
  33.     doc_width = document.body.clientWidth;
  34.     doc_height = document.body.clientHeight;
  35.   }
  36.  
  37.   dx = new Array();
  38.   xp = new Array();
  39.   yp = new Array();
  40.   am = new Array();
  41.   stx = new Array();
  42.   sty = new Array();
  43.   
  44.   for (i = 0; i < no; ++ i) {  
  45.     dx[i] = 0;                        // set coordinate variables
  46.     xp[i] = Math.random()*(doc_width-50);  // set position variables
  47.     yp[i] = Math.random()*doc_height;
  48.     am[i] = Math.random()*20;         // set amplitude variables
  49.     stx[i] = 0.02 + Math.random()/10; // set step variables
  50.     sty[i] = 0.7 + Math.random();     // set step variables
  51.     if (ns4up) {                      // set layers
  52.       if (i == 0) {
  53.         document.write("<layer name=\"dot"+ i +"\" left=\"15\" top=\"15\" visibility=\"show\"><a href=\"http://inet.hr/\"><img src=\"http://www.altan.hr/snow/dot.gif\" border=\"0\"></a></layer>");
  54.       } else {
  55.         document.write("<layer name=\"dot"+ i +"\" left=\"15\" top=\"15\" visibility=\"show\"><img src=\"http://www.altan.hr/snow/dot.gif\" border=\"0\"></layer>");
  56.       }
  57.     } else if (ie4up) {
  58.       if (i == 0) {
  59.         document.write("<div id=\"dot"+ i +"\" style=\"POSITION: absolute; Z-INDEX: "+ i +"; VISIBILITY: visible; TOP: 15px; LEFT: 15px;\"><a href=\"http://inet.hr/\"><img src=\"http://www.altan.hr/snow/dot.gif\" border=\"0\"></a></div>");
  60.       } else {
  61.         document.write("<div id=\"dot"+ i +"\" style=\"POSITION: absolute; Z-INDEX: "+ i +"; VISIBILITY: visible; TOP: 15px; LEFT: 15px;\"><img src=\"http://www.altan.hr/snow/dot.gif\" border=\"0\"></div>");
  62.       }
  63.     }
  64.   }
  65.   
  66.   function snowNS() {  // Netscape main animation function
  67.     for (i = 0; i < no; ++ i) {  // iterate for every dot
  68.       yp[i] += sty[i];
  69.       if (yp[i] > doc_height-50) {
  70.         xp[i] = Math.random()*(doc_width-am[i]-30);
  71.         yp[i] = 0;
  72.         stx[i] = 0.02 + Math.random()/10;
  73.         sty[i] = 0.7 + Math.random();
  74.         doc_width = self.innerWidth;
  75.         doc_height = self.innerHeight;
  76.       }
  77.       dx[i] += stx[i];
  78.       document.layers["dot"+i].top = yp[i];
  79.       document.layers["dot"+i].left = xp[i] + am[i]*Math.sin(dx[i]);
  80.     }
  81.     setTimeout("snowNS()", 10);
  82.   }
  83.  
  84.   function snowIE() {  // IE main animation function
  85.     for (i = 0; i < no; ++ i) {  // iterate for every dot
  86.       yp[i] += sty[i];
  87.       if (yp[i] > doc_height-50) {
  88.         xp[i] = Math.random()*(doc_width-am[i]-30);
  89.         yp[i] = 0;
  90.         stx[i] = 0.02 + Math.random()/10;
  91.         sty[i] = 0.7 + Math.random();
  92.         doc_width = document.body.clientWidth;
  93.         doc_height = document.body.clientHeight;
  94.       }
  95.       dx[i] += stx[i];
  96.       document.all["dot"+i].style.pixelTop = yp[i];
  97.       document.all["dot"+i].style.pixelLeft = xp[i] + am[i]*Math.sin(dx[i]);
  98.     }
  99.     setTimeout("snowIE()", 10);
  100.   }
  101.  
  102.   if (ns4up) {
  103.     snowNS();
  104.   } else if (ie4up) {
  105.     snowIE();
  106.   }
  107.