...

View Full Version : Changing bg of document my script dead



saldikey
08-01-2002, 05:24 PM
Could you tell me why this is not working? I put it in external file and calling it from <body> tag with unload

here is the script
function fadeout()
{
var
hex_variants=new Array(6)
hex_variants[0]="00"
hex_variants[1]="33"
hex_variants[2]="66"
hex_variants[3]="99"
hex_variants[4]="CC"
hex_variants[5]="FF"
for (i=0; i<=5; i++)
{
hexred=hex_variants[i]
for (j=0; j<=5; j++)
{
hexgreen=hex_variants[j]
for (k=0; k<=5; k++)
{
hexblue=hex_variants[k]
document.style.bgcolor='("#"+hexred+hexgreen+hexblue)';
}
}
}
}

I want bg change from balck to white when page unloads. I was trying it with IE6 and getting no errors. Or its just too fast?
Thank you for your time

x_goose_x
08-01-2002, 06:00 PM
<html>

<head>
<script>

t = 100 // higher the number longer it takes to change

bgcol = new Array();
bgcol[0] = "#000000";
bgcol[1] = "#202020";
bgcol[2] = "#333333";
bgcol[3] = "#505050";
bgcol[4] = "#666666";
bgcol[5] = "#808080";
bgcol[6] = "#999999";
bgcol[7] = "#C0C0C0";
bgcol[8] = "#CCCCCC";
bgcol[9] = "#f0f0f0";
bgcol[10] = "#ffffff";

c = 0;

function fadeout() {
document.body.style.backgroundColor = bgcol[c];
if (c<bgcol.length) {
c++
setTimeout("fadeout()",t);
}
}
</script>
</head>

<body onload="fadeout();" style="background-color: black;">

</body>

</html>

saldikey
08-01-2002, 06:34 PM
Thanks Goose, it works with onload. But I was trying to do it with unload. Now, I think its impossible, so I will do it on next page with onload.

Is my own script totally wrong.?In this line I am getting invalid property value:
document.body.style.backgroundColor='(#+hexred+hexgreen+hexblue)';


Sorry for syntax question:rolleyes:

x_goose_x
08-01-2002, 11:47 PM
Try with:

<body onBeforeUnload="fadeout();" style="background-color: black;">

IE ONLY!

saldikey
08-02-2002, 03:21 AM
x_goose_x - Thank you!
I got it working with onload on next page.

Than I am trying to set background image right after this fadeout finished.

I got line of code

document.body.style.background="url('image.jpg')" at you script and it works here:
-------------------------------------------------------
function fadeout() {
document.body.style.backgroundColor = bgcol[c];
if (c<bgcol.length) {
c++
setTimeout("fadeout()",t);
}
else {document.body.style.background="url('image.jpg')"}
}
-------------------------------------------------------------
What I am really tried is to make background change N images so I would get some fancy affects, but i was getting errors. Is it possible to make some kind of looping with images?
:confused: :confused: :confused:

x_goose_x
08-02-2002, 04:03 AM
Didn't test, but should work:



<html>

<head>
<script>

t = 100 // higher the number longer it takes to change

bgcol = new Array();
bgcol[0] = "image0.jpg";
bgcol[1] = "image1.jpg";
bgcol[2] = "image2.jpg";
bgcol[3] = "image3.jpg";
bgcol[4] = "image4.jpg";
bgcol[5] = "image5.jpg";
bgcol[6] = "image6.jpg";
bgcol[7] = "image7.jpg";
bgcol[8] = "image8.jpg";
bgcol[9] = "image9.jpg";
bgcol[10] = "image10.jpg";

c = 0;

function fadeout() {
document.body.style.background = eval("url('"+bgcol[c]+"')");
if (c<bgcol.length) {
c++
setTimeout("fadeout()",t);
}
}
</script>
</head>

<body onload="fadeout();" style="background-color: black;">

</body>

</html>

x_goose_x
08-02-2002, 04:03 AM
Why not just kae an animated GIF?

saldikey
08-02-2002, 04:26 AM
ha-ha-ha :D :D :D :D see previous posting and my slogun

x_goose_x
08-02-2002, 04:56 AM
"kae" was uspposed to be "use" . I can't type.

saldikey
08-02-2002, 07:17 PM
its not about kae, its about that gif is easy



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum