Schnee(9)

Moderator: HTML-Laie

Antworten
Benutzeravatar
Hape
Administrator
Beiträge: 336
Registriert: Fr 22. Mai 2020, 00:33

Schnee(9)

Beitrag von Hape »

Hier noch ein einfaches Schneescript:

Code: Alles auswählen

<script language="javascript">
ns6 = document.getElementById;
ns  = document.layers;
ie  = document.all;
/*******************[AccessCSS]***********************************/
function accessCSS(layerID)        {                                                                                                                                    //
  if(ns6){ return document.getElementById(layerID).style;}     //
   else if(ie){ return document.all[layerID].style; }         //
    else if(ns){ return document.layers[layerID]; }          //
}/***********************************************************/
/**************************[move Layer]*************************************/
function move(layer,x,y)  { accessCSS(layer).left=x; accessCSS(layer).top = y; }
function browserBredde() {
        if (window.innerWidth) return window.innerWidth;
        else if (document.body.clientWidth) return document.body.clientWidth;
        else return 1024;
}

function browserHoyde() {

            if (window.innerHeight) return window.innerHeight;
            else if (document.body.clientHeight) return document.body.clientHeight;
            else return 800;
}

function makeDiv(objName,parentDiv,w,h,content,x,y,overfl,positionType)
{
          // positionType could be 'absolute' or 'relative'

                if (parentDiv==null) parentDiv='body';

    var oDiv = document.createElement ("DIV");
    oDiv.id = objName;

                 if (w) oDiv.style.width = w;
                if (h) oDiv.style.height= h;
if (content) oDiv.innerHTML=content;
          if (positionType==null) positionType="absolute";
                oDiv.style.position = positionType;
                if (x) oDiv.style.left=x; else oDiv.style.left=-2000;
                if (y) oDiv.style.top=y; else oDiv.style.top=-2000;
if (overfl) oDiv.style.overflow=overfl; else oDiv.style.overflow="hidden";
    eval('  document.'+parentDiv+'.appendChild (oDiv);  ');

    delete oDiv;
}

var snowC=0;
var x = new Array();
var y = new Array();
var speed = new Array();
var t=0;
var cC = new Array();
var ra = new Array();

function makeSnow() {
        x[snowC] = Math.round(Math.random()*(browserBredde()-60));
        y[snowC] = 10;
        makeDiv("snow"+snowC,"body",24,24,'<img src="http://bbv-sitemaker.bplaced.net/Javascripte/Images/diverseimages/snow.gif">');
        speed[snowC] = Math.round(Math.random()*8)+1;
        cC[snowC]=Math.random()*10;
        ra[snowC] = Math.random()*7;
        snowC++;

}
function moveSnow() {
        var r = Math.round(Math.random()*100);
        if (r>70 && snowC<20) makeSnow();

        for (t=0;t<snowC;t++) {
                y[t]+=speed[t];move("snow"+t,x[t],y[t]);
                if (y[t]>browserHoyde()-50) {y[t] = 10;x[t] = Math.round(Math.random()*(browserBredde()-60));}
                cC[t]+=0.01;
                x[t]+=Math.cos(cC[t]*ra[t]);

        }

        setTimeout('moveSnow()',20);
}

moveSnow();
</script>
Demoseite hierzu: Schnee(9)
snow.gif
snow.gif (560 Bytes) 6506 mal betrachtet

Antworten