Tulos

Selaintuen salliessa talvella sataa lunta ja kesällä taas vettä. Muut JS-selaimet saavat ilmoituksen vuodenajasta ja sateettomuudesta.

Koodi

Tämä tulee BODY-osastoon

<script type="text/javascript">
<!--
var NytOn = new Date();

// ao. palauttaa arvot 0-11

var Kkausi = NytOn.getMonth();

// määritellään vuodenaika talveksi tai kesäksi

var Vaika;
     if (Kkausi == 10) Vaika = "talvi";
else if (Kkausi == 11) Vaika = "talvi";
else if (Kkausi == 0) Vaika = "talvi";
else if (Kkausi == 1) Vaika = "talvi";
else if (Kkausi == 2) Vaika = "talvi";

// yo:ssa marras - maalis määritetty talveksi

else Vaika = "kesä"

// yo:ssa loput määritetty kesäksi

if((document.all || document.layers) && (Vaika=="talvi")) {

// suoritetaan talveen sopivaa koodia mikäli
// selain täyttää vaatimukset

var no = 24; // hiutaleiden määrä
   var speed = 8; // hiutaleiden liikkumisnopeus, pienempi nro. nopeampi liike
   var kuva = "../kuvat/hiutale.gif"; //polku kuvaasi

   var flag;
   var ns4up = (document.layers) ? 1 : 0;  // browser sniffer
   var ie4up = (document.all) ? 1 : 0;

   var dx, xp, yp;    // coordinate and position variables
   var am, stx, sty;  // amplitude and step variables
   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;
   }
   dx = new Array();
   xp = new Array();
   yp = new Array();
   amx = new Array();
   amy = new Array();
   stx = new Array();
   sty = new Array();
   flag = new Array();
   for (i = 0; i < no; ++ i) {
   dx[i] = 0;                        // set coordinate variables
   xp[i] = Math.random()*(doc_width-30)+10;  // set position variables
   yp[i] = Math.random()*doc_height;
   amy[i] = 12+ Math.random()*20;         // set amplitude variables
   amx[i] = 10+ Math.random()*40;
   stx[i] = 0.02 + Math.random()/10; // set step variables
   sty[i] = 0.7 + Math.random();     // set step variables
   flag[i] = (Math.random()>0.5)?1:0;
   if (ns4up) {                      // set layers
   if (i == 0) {
   document.write("<layer name=\"dot"+ i +"\" left=\"15\" ");
   document.write("top=\"15\" visibility=\"show\"><img src=\"");
   document.write(kuva+ "\" border=\"0\"></layer>");
   } else {
   document.write("<layer name=\"dot"+ i +"\" left=\"15\" ");
   document.write("top=\"15\" visibility=\"show\"><img src=\"");
   document.write(kuva+ "\" border=\"0\"></layer>");
   }
   } else
   if (ie4up) {
   if (i == 0) {
   document.write("<div id=\"dot"+ i +"\" style=\"POSITION: ");
   document.write("absolute; Z-INDEX: "+ i +"; VISIBILITY: ");
   document.write("visible; TOP: 15px; LEFT: 15px;\"><img src=\"");
   document.write(kuva+ "\" border=\"0\"></div>");
   } else {
   document.write("<div id=\"dot"+ i +"\" style=\"POSITION: ");
   document.write("absolute; Z-INDEX: "+ i +"; VISIBILITY: ");
   document.write("visible; TOP: 15px; LEFT: 15px;\"><img src=\"");
   document.write(kuva+ "\" border=\"0\"></div>");
   }
   }
   }

   function snowNS() {  // Netscape main animation function
   for (i = 0; i < no; ++ i) {  // iterate for every dot
   if (yp[i] > doc_height-50) {
   xp[i] = 10+ Math.random()*(doc_width-amx[i]-30);
   yp[i] = 0;
   flag[i]=(Math.random()<0.5)?1:0;
   stx[i] = 0.02 + Math.random()/10;
   sty[i] = 0.7 + Math.random();
   doc_width = self.innerWidth;
   doc_height = self.innerHeight;
   }
   if (flag[i])
   dx[i] += stx[i];
   else
   dx[i] -= stx[i];
   if (Math.abs(dx[i]) > Math.PI) {
   yp[i]+=Math.abs(amy[i]*dx[i]);
   xp[i]+=amx[i]*dx[i];
   dx[i]=0;
   flag[i]=!flag[i];
   }
   document.layers["dot"+i].top = yp[i] + amy[i]*(Math.abs(Math.sin(dx[i])+dx[i]));
   document.layers["dot"+i].left = xp[i] + amx[i]*dx[i];

   }
   setTimeout("snowNS()", speed);
   }

   function snowIE() {  // IE main animation function
   for (i = 0; i < no; ++ i) {  // iterate for every dot
   if (yp[i] > doc_height-50) {
   xp[i] = 10+ Math.random()*(doc_width-amx[i]-30);
   yp[i] = 0;
   stx[i] = 0.02 + Math.random()/10;
   sty[i] = 0.7 + Math.random();
   flag[i]=(Math.random()<0.5)?1:0;
   doc_width = document.body.clientWidth;
   doc_height = document.body.clientHeight;
   }
   if (flag[i])
   dx[i] += stx[i];
   else
   dx[i] -= stx[i];
   if (Math.abs(dx[i]) > Math.PI) {
   yp[i]+=Math.abs(amy[i]*dx[i]);
   xp[i]+=amx[i]*dx[i];
   dx[i]=0;
   flag[i]=!flag[i];
   }

   document.all["dot"+i].style.pixelTop = yp[i] + amy[i]*(Math.abs(Math.sin(dx[i])+dx[i]));
   document.all["dot"+i].style.pixelLeft = xp[i] + amx[i]*dx[i];
   }
   setTimeout("snowIE()", speed);
   }

   if (ns4up) {
   snowNS();
   } else if (ie4up) {
   snowIE();
   }
// talvikoodi loppuu
}

if((document.all || document.layers) && (Vaika=="kesä")) {

// suoritetaan kesään sopivaa koodia mikäli
// selain täyttää vaatimukset
// Original: Matthew Musgrove (muskrat@lvnworth.com)
   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 < no; ++ i) {  
   initRain();
   if (ns4up) {
   if (i == 0) {
   document.write("<layer name=\"dot"+ i +"\" left=\"1\" ");
   document.write("top=\"1\" visibility=\"show\"><font color=\"blue\">");
   document.write(",</font></layer>");
   }
   else {
   document.write("<layer name=\"dot"+ i +"\" left=\"1\" ");
   document.write("top=\"1\" visibility=\"show\"><font color=\"blue\">");
   document.write(",</font></layer>");
      }
   }
   else 
   if (ie4up) {
   if (i == 0) {
   document.write("<div id=\"dot"+ i +"\" style=\"POSITION: ");
   document.write("absolute; Z-INDEX: "+ i +"; VISIBILITY: ");
   document.write("visible; TOP: 15px; LEFT: 15px;\"><font color=\"blue\">");
   document.write(",</font></div>");
   }
   else {
   document.write("<div id=\"dot"+ i +"\" style=\"POSITION: ");
   document.write("absolute; Z-INDEX: "+ i +"; VISIBILITY: ");
   document.write("visible; TOP: 15px; LEFT: 15px;\"><font color=\"blue\">");
   document.write(",</font></div>");
         }
      }
   }
   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 < no; ++ i) {
   updateRain();
   if ((x[i] <= 1) || (x[i] >= (doc_width - 20)) || (y[i] >= (doc_height - 20))) {
   makeRain();
   doc_width = self.innerWidth;
   doc_height = self.innerHeight;
   }
   document.layers["dot"+i].top = y[i];
   document.layers["dot"+i].left = x[i];
   }
   setTimeout("raindropNS()", speed);
   }
   function raindropIE() {
   for (i = 0; i < no; ++ i) {
   updateRain();
   if ((x[i] <= 1) || (x[i] >= (doc_width - 20)) || (y[i] >= (doc_height - 20))) {
   makeRain();
   doc_width = document.body.clientWidth;
   doc_height = document.body.clientHeight;
   }
   document.all["dot"+i].style.pixelTop = y[i];
   document.all["dot"+i].style.pixelLeft = x[i];
   }
   setTimeout("raindropIE()", speed);
   }
   if (ns4up) {
   raindropNS();
   }
   else
   if (ie4up) {
   raindropIE();
   }
// kesäkoodi loppuu
}

// jos ei DHTML-selain:

if (!(ns4up || ie4up))

// suoritetaan muu koodi, vaikka:

{document.write('Ilmoitusluontoinen asia: nyt on ' + Vaika + ' eikä edes sada!')}
//-->
</script>
Weppipakin kotisivulle