home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2002 July / APC0702D1.iso / isp / tpgi / Products / snow.js < prev    next >
Encoding:
Text File  |  2000-12-11  |  3.5 KB  |  101 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 = 10; // snow number
  6. var speed = 25; // smaller number moves the snow faster
  7. var snowflake = "flake-small.gif";
  8. var keith = 1;
  9. var sammmy = 2;
  10.  
  11. var ns4up = (document.layers) ? 1 : 0;  // browser sniffer
  12. var ie4up = (document.all) ? 1 : 0;
  13. var dx, xp, yp;    // coordinate and position variables
  14. var am, stx, sty;  // amplitude and step variables
  15. var h, doc_width = 600, doc_height = 500;
  16. if (ns4up) {
  17.   doc_width = self.innerWidth;
  18.   doc_height = self.innerHeight;
  19. } else if (ie4up) {
  20.   doc_width = 600;
  21.   doc_height = 500;
  22. }
  23. dx = new Array();
  24. xp = new Array();
  25. yp = new Array();
  26. am = new Array();
  27. stx = new Array();
  28. sty = new Array();
  29. for (h = 0; h < no; ++ h) {  
  30.   dx[h] = 0;                        // set coordinate variables
  31.   xp[h] = Math.random()*(doc_width-50);  // set position variables
  32.   yp[h] = Math.random()*doc_height;
  33.   am[h] = Math.random()*20;         // set amplitude variables
  34.   stx[h] = 0.02 + Math.random()/10; // set step variables
  35.   sty[h] = 0.7 + Math.random();     // set step variables
  36.   if (ns4up) {                      // set layers
  37.     if (h == 0) {
  38.       document.write("<layer name=\"dot"+ h +"\" left=\"15\" ");
  39.       document.write("top=\"15\" visibility=\"show\"><img src=\"");
  40.       document.write(snowflake + "\" border=\"0\"></layer>");
  41.     } else {
  42.       document.write("<layer name=\"dot"+ h +"\" left=\"15\" ");
  43.       document.write("top=\"15\" visibility=\"show\"><img src=\"");
  44.       document.write(snowflake + "\" border=\"0\"></layer>");
  45.     }
  46.   } else if (ie4up) {
  47.     if (h == 0) {
  48.       document.write("<div id=\"dot"+ h +"\" style=\"POSITION: ");
  49.       document.write("absolute; Z-INDEX: "+ h +"; VISIBILITY: ");
  50.       document.write("visible; TOP: 15px; LEFT: 15px;\"><img src=\"");
  51.       document.write(snowflake + "\" border=\"0\"></div>");
  52.     } else {
  53.       document.write("<div id=\"dot"+ h +"\" style=\"POSITION: ");
  54.       document.write("absolute; Z-INDEX: "+ h +"; VISIBILITY: ");
  55.       document.write("visible; TOP: 15px; LEFT: 15px;\"><img src=\"");
  56.       document.write(snowflake + "\" border=\"0\"></div>");
  57.     }
  58.   }
  59. }
  60. function snowNS() {  // Netscape main animation function
  61.   for (h = 0; h < no; ++ h) {  // iterate for every dot
  62.     yp[h] += sty[h];
  63.     if (yp[h] > doc_height-50) {
  64.       xp[h] = Math.random()*(doc_width-am[h]-30);
  65.       yp[h] = 0;
  66.       stx[h] = 0.02 + Math.random()/10;
  67.       sty[h] = 0.7 + Math.random();
  68.       doc_width = self.innerWidth;
  69.       doc_height = self.innerHeight;
  70.     }
  71.     dx[h] += stx[h];
  72.     document.layers["dot"+h].top = yp[h];
  73.     document.layers["dot"+h].left = xp[h] + am[h]*Math.sin(dx[h]);
  74.   }
  75.   setTimeout("snowNS()", speed);
  76. }
  77.  
  78. function snowIE() {  // IE main animation function
  79.   for (h = 0; h < no; ++ h) {  // iterate for every dot
  80.     yp[h] += sty[h];
  81.     if (yp[h] > doc_height-50) {
  82.       xp[h] = Math.random()*(doc_width-am[h]-30);
  83.       yp[h] = 0;
  84.       stx[h] = 0.02 + Math.random()/10;
  85.       sty[h] = 0.7 + Math.random();
  86.       doc_width = document.body.clientWidth;
  87.       doc_height = document.body.clientHeight;
  88.     }
  89.     dx[h] += stx[h];
  90.     document.all["dot"+h].style.pixelTop = yp[h];
  91.     document.all["dot"+h].style.pixelLeft = xp[h] + am[h]*Math.sin(dx[h]);
  92.   }
  93.   setTimeout("snowIE()", speed);
  94. }
  95.  
  96. if (ns4up) {
  97.   snowNS();
  98. } else if (ie4up) {
  99.   snowIE();
  100. }
  101.