Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-01-2002, 04:24 PM   PM User | #1
saldikey
New Coder

 
Join Date: Jun 2002
Location: WI - is not only cows and beer
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
saldikey is an unknown quantity at this point
Question Changing bg of document my script dead

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
__________________
"Intelegence complicates.
Wisdom simplifies."
Mason Cooley

Last edited by saldikey; 08-01-2002 at 04:37 PM..
saldikey is offline   Reply With Quote
Old 08-01-2002, 05:00 PM   PM User | #2
x_goose_x
Regular Coder

 
Join Date: Jun 2002
Location: Montreal, Canada
Posts: 644
Thanks: 0
Thanked 0 Times in 0 Posts
x_goose_x is an unknown quantity at this point
<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>
x_goose_x is offline   Reply With Quote
Old 08-01-2002, 05:34 PM   PM User | #3
saldikey
New Coder

 
Join Date: Jun 2002
Location: WI - is not only cows and beer
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
saldikey is an unknown quantity at this point
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
__________________
"Intelegence complicates.
Wisdom simplifies."
Mason Cooley
saldikey is offline   Reply With Quote
Old 08-01-2002, 10:47 PM   PM User | #4
x_goose_x
Regular Coder

 
Join Date: Jun 2002
Location: Montreal, Canada
Posts: 644
Thanks: 0
Thanked 0 Times in 0 Posts
x_goose_x is an unknown quantity at this point
Try with:

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

IE ONLY!
x_goose_x is offline   Reply With Quote
Old 08-02-2002, 02:21 AM   PM User | #5
saldikey
New Coder

 
Join Date: Jun 2002
Location: WI - is not only cows and beer
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
saldikey is an unknown quantity at this point
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?
__________________
"Intelegence complicates.
Wisdom simplifies."
Mason Cooley
saldikey is offline   Reply With Quote
Old 08-02-2002, 03:03 AM   PM User | #6
x_goose_x
Regular Coder

 
Join Date: Jun 2002
Location: Montreal, Canada
Posts: 644
Thanks: 0
Thanked 0 Times in 0 Posts
x_goose_x is an unknown quantity at this point
Didn't test, but should work:

Code:
<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 is offline   Reply With Quote
Old 08-02-2002, 03:03 AM   PM User | #7
x_goose_x
Regular Coder

 
Join Date: Jun 2002
Location: Montreal, Canada
Posts: 644
Thanks: 0
Thanked 0 Times in 0 Posts
x_goose_x is an unknown quantity at this point
Why not just kae an animated GIF?
x_goose_x is offline   Reply With Quote
Old 08-02-2002, 03:26 AM   PM User | #8
saldikey
New Coder

 
Join Date: Jun 2002
Location: WI - is not only cows and beer
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
saldikey is an unknown quantity at this point
ha-ha-ha see previous posting and my slogun
__________________
"Intelegence complicates.
Wisdom simplifies."
Mason Cooley
saldikey is offline   Reply With Quote
Old 08-02-2002, 03:56 AM   PM User | #9
x_goose_x
Regular Coder

 
Join Date: Jun 2002
Location: Montreal, Canada
Posts: 644
Thanks: 0
Thanked 0 Times in 0 Posts
x_goose_x is an unknown quantity at this point
"kae" was uspposed to be "use" . I can't type.
x_goose_x is offline   Reply With Quote
Old 08-02-2002, 06:17 PM   PM User | #10
saldikey
New Coder

 
Join Date: Jun 2002
Location: WI - is not only cows and beer
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
saldikey is an unknown quantity at this point
its not about kae, its about that gif is easy
__________________
"Intelegence complicates.
Wisdom simplifies."
Mason Cooley
saldikey is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:12 AM.


Advertisement
Log in to turn off these ads.