home *** CD-ROM | disk | FTP | other *** search
/ Enter 2001 July / EnterCD7.iso / Off-line / w4 / strona / snieg.js < prev    next >
Encoding:
Text File  |  2001-05-18  |  3.4 KB  |  100 lines

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