<SCRIPT LANGUAGE='JavaScript' TYPE='TEXT/JAVASCRIPT'>
rot= 00; 
blau = 99; 
wahr = true; 

function drehum() { 
if(wahr == true) { rot++; blau--; 

if(rot == 00) { rot++; blau--; wahr = true; 

if(wahr == false) { rot--; blau++; 

if(rot == 100) { rot--; blau++; wahr = false; 

document.bgColor=rot +"33"+ blau; 
setTimeout ("drehum()",100); 
status="rot="+rot+" blau="+blau+" und der Gruenanteil="+document.bgColor //just to debug
}


<body onLoad="drehum()">

 

 

 

First assignment - fading one backgroundcolor to the next.

Talking about this function. In the script is typed:

functionBGChange()...The function is in the head of the page and waiting for calling. So there has to be  in the body the call for it. In this case: BGChange();. As it is there the function to change the background can do the work. 

The function also has a command about the timing. This is in the following part:

setTimeout ("BGChange()",10);.....this means repeat every 10 Milliseconds. Changing to maybe 100 or 1000 = 1 second will slow down the speed.

there are three variables: b=10, f= 99, and a= true...

the function tells that if a==true b counts +1 and f counts -1

and it tells that a is true if b=10 (what is defined in b=10)

 

the document.bgColor= b + 00 + f  (means 100099) at the start then 110098 then 120097 and so on........instead of 00 in the middle I can also write another pair like for example ff or cc or 35 for to change the colors I think so. I think to remember that the first two digits are the red color amount, the middle two digits the green amount and the last pair the blue amount

setTimeout ("BGChange()",10); tells about the timing

The Body tag tells that BGChange should start at the beginning

 

After playing with the script I gave the constant numbers inside the color number the names 33 instead of 00(middle of the document.bgColor) and changed the speed to 100 for to slow down a bit.

after talking to a friend I also added a part to the script to watch out in the statusbar what happens:

status="b=2+b+" f0"+f+" and the bgcolor="+document.bgColor

When I finally started to understand more I realized that the programmer is giving the name of the variables. So I changed my variables to German words for to clear the dust a bit more :).

Then I added another part to the script. The numbers count into the opposite direction after reaching the goal (means b=99 f=00...so it should start to go back again, that there was an endless turn around).

I told if b=100, then a= false and it should start to count b-- and f++

You ask me if I did it by myself? No. But I am curious to learn more about. So am I talking about what is going through my mind. The best thing on internet is that you always can find good friends for getting answers. Well one of this was the suggestion to repeat the whole thing backwards.  

 

back