How exactly does a background fader script work???

N

Nick

Does a background fader work by...


A) Changing the color after a long 'loop' statement???

B) Changing the color, then waiting a bit, then changing the color
again???


To me it seems B would be less cpu/browser intensive. Does anyone know
how exactly this works and an example script? Thanks! -Nick
 
N

Nick

Well I found a good simple example script.

The setTimeout() function was the snip I guess I was looking for. Ive
seen many other scripts that just rely on a loop to change the colors
- the problem though - faster cpu, the faster colors change; not very
uniform. The setTimeout() fixes that. Here it is!!!



<script language="Javascript">
// 'i' increments the RGB values
// 't' changes the frequency of time
var t = "10";
function fader(i) {
var RGBstring = "rgb("+i+","+i+","+i+")";
document.bgColor = RGBstring;
setTimeout("fader("+(i-1)+")",t);
}
</script>

<FORM NAME="background">
<INPUT TYPE="button" VALUE="Start" onClick="fader(255)">
</FORM>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,077
Messages
2,570,566
Members
47,202
Latest member
misc.

Latest Threads

Top