How to make a webpage background static in javascript?

Discussion in 'Web Design and Development' started by boohoowoofoo, Feb 24, 2011.

  1. boohoowoofoo macrumors newbie

    Joined:
    Nov 28, 2007
    #1
    Hi guys!

    First off some people might enjoy this script: It will allow your page to change the wallpaper each and every time you refresh! It will be for my portfolio page where I have graphic design pieces. Anyway, I have my wallpaper, but I do not know what code I have to type in so that the wallpaper is static, and the website text/content scrolls over without the image scrolling.

    here is the code:

    <SCRIPT LANGUAGE="JavaScript">
    <!--
    today=new Date();
    jran=today.getTime();
    var number = 11;
    var random_number="";
    var image="";
    var text_color="";
    ia=9301;
    ic=49297;
    im=233280;
    jran = (jran*ia+ic) % im;
    random_number = Math.ceil( (jran/(im*1.0)) *number);
    // Loads the appropriate image and text color based on random number.
    if (random_number==1) {
    image="images/pic1.jpg";
    }
    if (random_number==2) {
    image="images/pic2.jpg";
    }
    if (random_number==3) {
    image="images/pic3.jpg";
    }
    if (random_number==4) {
    image="images/pic4.jpg";
    }
    if (random_number==5) {
    image="images/pic5.jpg";
    }
    if (random_number==6) {
    image="images/pic6.jpg";
    }
    if (random_number==7) {
    image="images/pic2.jpg";
    }
    if (random_number==8) {
    image="images/pic3.jpg";
    }
    if (random_number==9) {
    image="images/pic4.jpg";
    }
    if (random_number==10) {
    image="images/pic5.jpg";
    }
    if (random_number==11) {
    image="images/pic6.jpg";
    }
    // End -->
    </SCRIPT>

    <div id=EchoTopic>

    <SCRIPT LANGUAGE="JavaScript">

    <!-- Begin
    document.open();
    document.write("<BODY BACKGROUND='"+image+"'>");
    document.write("<CENTER></CENTER>");
    // End -->
    </SCRIPT>

    if anyone could help me I would appreciate it!

    I already have the wallpaper static in my css but that does not seem to do anything since I am trying to change the wallpaper after every refresh.

    thank you again!
     
  2. boohoowoofoo thread starter macrumors newbie

    Joined:
    Nov 28, 2007
    #2
    Does anyone know if there is possibly a CSS code I can use instead? I shall google it till then but my search isn't bringing much up.

    I just really want the background to be static while being able to rotate as the user refreshes the site. :)
     
  3. timmy67 macrumors newbie

    Joined:
    Aug 8, 2010
    #3
    <style>
    <!--
    body {
    background-image: url(image.gif);
    background-repeat: no-repeat;
    background-attachment: fixed;
    }
    //-->
    </style>
     
  4. boohoowoofoo thread starter macrumors newbie

    Joined:
    Nov 28, 2007
    #4
    removed the first line specifying a specific background. It worked!

    Thank you Sir Timmy67 :)

    I just wanted to respond incase someone was deciding to design their site in a similar way. Thanks again
     

Share This Page