home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 February / Chip_2001-02_cd1.bin / firmy / Suma / SNOW.JS < prev    next >
Text File  |  2001-01-10  |  3KB  |  99 lines

  1. <!-- Original:  Altan (snow@altan.hr) -->
  2. <!-- Web Site:  http://www.altan.hr/snow -->
  3. <!-- Smaller flakes, subtle snowfall variables, code beautifcation and makeSnow function by NoSLZZP -->
  4.  
  5. var no = 5; // snow number
  6. var speed = 15; // smaller number moves the snow faster
  7. var snowflake = "flake-small.gif";
  8.  
  9. var ns4up = (document.layers) ? 1 : 0;  // browser sniffer
  10. var ie4up = (document.all) ? 1 : 0;
  11. var dx, xp, yp;    // coordinate and position variables
  12. var am, stx, sty;  // amplitude and step variables
  13. var i, doc_width = 400, doc_height = 500;
  14. if (ns4up) {
  15.   doc_width = self.innerWidth;
  16.   doc_height = self.innerHeight;
  17. } else if (ie4up) {
  18.   doc_width = 500;
  19.   doc_height = 500;
  20. }
  21. dx = new Array();
  22. xp = new Array();
  23. yp = new Array();
  24. am = new Array();
  25. stx = new Array();
  26. sty = new Array();
  27. for (i = 0; i < no; ++ i) {  
  28.   dx[i] = 0;                        // set coordinate variables
  29.   xp[i] = Math.random()*(doc_width-50);  // set position variables
  30.   yp[i] = Math.random()*doc_height;
  31.   am[i] = Math.random()*20;         // set amplitude variables
  32.   stx[i] = 0.02 + Math.random()/10; // set step variables
  33.   sty[i] = 0.7 + Math.random();     // set step variables
  34.   if (ns4up) {                      // set layers
  35.     if (i == 0) {
  36.       document.write("<layer name=\"dot"+ i +"\" left=\"15\" ");
  37.       document.write("top=\"15\" visibility=\"show\"><img src=\"");
  38.       document.write(snowflake + "\" border=\"0\"></layer>");
  39.     } else {
  40.       document.write("<layer name=\"dot"+ i +"\" left=\"15\" ");
  41.       document.write("top=\"15\" visibility=\"show\"><img src=\"");
  42.       document.write(snowflake + "\" border=\"0\"></layer>");
  43.     }
  44.   } else if (ie4up) {
  45.     if (i == 0) {
  46.       document.write("<div id=\"dot"+ i +"\" style=\"POSITION: ");
  47.       document.write("absolute; Z-INDEX: "+ i +"; VISIBILITY: ");
  48.       document.write("visible; TOP: 15px; LEFT: 15px;\"><img src=\"");
  49.       document.write(snowflake + "\" border=\"0\"></div>");
  50.     } else {
  51.       document.write("<div id=\"dot"+ i +"\" style=\"POSITION: ");
  52.       document.write("absolute; Z-INDEX: "+ i +"; VISIBILITY: ");
  53.       document.write("visible; TOP: 15px; LEFT: 15px;\"><img src=\"");
  54.       document.write(snowflake + "\" border=\"0\"></div>");
  55.     }
  56.   }
  57. }
  58. function snowNS() {  // Netscape main animation function
  59.   for (i = 0; i < no; ++ i) {  // iterate for every dot
  60.     yp[i] += sty[i];
  61.     if (yp[i] > doc_height-50) {
  62.       xp[i] = Math.random()*(doc_width-am[i]-30);
  63.       yp[i] = 0;
  64.       stx[i] = 0.02 + Math.random()/10;
  65.       sty[i] = 0.7 + Math.random();
  66.       doc_width = self.innerWidth;
  67.       doc_height = self.innerHeight;
  68.     }
  69.     dx[i] += stx[i];
  70.     document.layers["dot"+i].top = yp[i];
  71.     document.layers["dot"+i].left = xp[i] + am[i]*Math.sin(dx[i]);
  72.   }
  73.   setTimeout("snowNS()", speed);
  74. }
  75.  
  76. function snowIE() {  // IE main animation function
  77.   for (i = 0; i < no; ++ i) {  // iterate for every dot
  78.     yp[i] += sty[i];
  79.     if (yp[i] > doc_height-50) {
  80.       xp[i] = Math.random()*(doc_width-am[i]-30);
  81.       yp[i] = 0;
  82.       stx[i] = 0.02 + Math.random()/10;
  83.       sty[i] = 0.7 + Math.random();
  84.       doc_width = document.body.clientWidth;
  85.       doc_height = document.body.clientHeight;
  86.     }
  87.     dx[i] += stx[i];
  88.     document.all["dot"+i].style.pixelTop = yp[i];
  89.     document.all["dot"+i].style.pixelLeft = xp[i] + am[i]*Math.sin(dx[i]);
  90.   }
  91.   setTimeout("snowIE()", speed);
  92. }
  93.  
  94. if (ns4up) {
  95.   snowNS();
  96. } else if (ie4up) {
  97.   snowIE();
  98. }
  99.