Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Jun 2002
    Location
    WI - is not only cows and beer
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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
    Last edited by saldikey; 08-01-2002 at 04:37 PM.
    "Intelegence complicates.
    Wisdom simplifies."
    Mason Cooley

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <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>

  • #3
    New Coder
    Join Date
    Jun 2002
    Location
    WI - is not only cows and beer
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try with:

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

    IE ONLY!

  • #5
    New Coder
    Join Date
    Jun 2002
    Location
    WI - is not only cows and beer
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Why not just kae an animated GIF?

  • #8
    New Coder
    Join Date
    Jun 2002
    Location
    WI - is not only cows and beer
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ha-ha-ha see previous posting and my slogun
    "Intelegence complicates.
    Wisdom simplifies."
    Mason Cooley

  • #9
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts
    "kae" was uspposed to be "use" . I can't type.

  • #10
    New Coder
    Join Date
    Jun 2002
    Location
    WI - is not only cows and beer
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    its not about kae, its about that gif is easy
    "Intelegence complicates.
    Wisdom simplifies."
    Mason Cooley


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •