Click to See Complete Forum and Search --> : Help editing bg fader


Karr
01-29-2003, 09:22 AM
I want to use the code below but I want to make it fade black to
white (instead of white to black.

Thanks in advance for any help or suggestions!


here is the code I borrowed...

<SCRIPT LANGUAGE="Javascript">
<!-- Original: Fred S. Tucker (Slurpie_Tucker@yahoo.com) -->
<!-- Web URL: http://members.tripod.com/~Slurpies_Page -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function makearray(n) {
this.length = n;
for(var i = 1; i <= n; i++)
this[i] = 0;
return this;
}
hexa = new makearray(16);
for(var i = 0; i < 10; i++)
hexa[i] = i;
hexa[10]="a"; hexa[11]="b"; hexa[12]="c";
hexa[13]="d"; hexa[14]="e"; hexa[15]="f";
function hex(i) {
if (i < 0)
return "00";
else if (i > 255)
return "ff";
else
return "" + hexa[Math.floor(i/16)] + hexa[i%16];
}
function setbgColor(r, g, b) {
var hr = hex(r); var hg = hex(g); var hb = hex(b);
document.bgColor = "#"+hr+hg+hb;
}
function fade(sr, sg, sb, er, eg, eb, step) {
for(var i = 0; i <= step; i++) {
setbgColor(
Math.floor(sr * ((step-i)/step) + er * (i/step)),
Math.floor(sg * ((step-i)/step) + eg * (i/step)),
Math.floor(sb * ((step-i)/step) + eb * (i/step)));
}
}
function fadein() {
fade(240,232,223,0,0,0,255);
}
fadein();
window.location="http://www.yoursite.com/fadein-page2.html";
// End -->
</SCRIPT>

Sergey Smirnov
01-29-2003, 11:58 AM
To reverse fading, just exchange 6 first parameters. I.e

fade(0,0,0,255,255,255,255);


However, I am not sure this code will work correct everywhere. At least, my browser jumps to new location without fading.

Solution may be the following: add empty body and call fadein function from onload. At the end of fadein, insert the redirection instruction. The result code is bellow. You just have to replace site URL with your own one.

<SCRIPT LANGUAGE="Javascript">
<!-- Original: Fred S. Tucker (Slurpie_Tucker@yahoo.com) -->
<!-- Web URL: http://members.tripod.com/~Slurpies_Page -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function makearray(n) {
this.length = n;
for(var i = 1; i <= n; i++)
this[i] = 0;
return this;
}
hexa = new makearray(16);
for(var i = 0; i < 10; i++)
hexa[i] = i;
hexa[10]="a"; hexa[11]="b"; hexa[12]="c";
hexa[13]="d"; hexa[14]="e"; hexa[15]="f";
function hex(i) {
if (i < 0)
return "00";
else if (i > 255)
return "ff";
else
return "" + hexa[Math.floor(i/16)] + hexa[i%16];
}
function setbgColor(r, g, b) {
var hr = hex(r); var hg = hex(g); var hb = hex(b);
document.bgColor = "#"+hr+hg+hb;
}
function fade(sr, sg, sb, er, eg, eb, step) {
for(var i = 0; i <= step; i++) {
setbgColor(
Math.floor(sr * ((step-i)/step) + er * (i/step)),
Math.floor(sg * ((step-i)/step) + eg * (i/step)),
Math.floor(sb * ((step-i)/step) + eb * (i/step)));
}
}
function fadein() {
fade(0,0,0,255,255,255,255);
window.location.replace("http://www.exadel.com");
}

// End -->
</SCRIPT>
<body onload="fadein()"></body>

Karr
01-29-2003, 12:28 PM
Thank You Sergey! Works like a charm.