SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict djh's Avatar
    Join Date
    Apr 2000
    Location
    Long Beach, CA
    Posts
    333
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    rotate background images

    Hi.

    I want to rotate (flip through) 4 images as a background... Anyone know how to code in javascript?

    If not, anyone know how to display a random image (of the 4) every time the page reloads?

    thanks,
    Dave

  2. #2
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am already using something like this. It works beautifully. This goes in the HEAD tag:

    <script language="JavaScript">
    <!--

    function randomImage() {
    pic = new Array();
    pic[0] = 'images/hdr_green.jpg';
    pic[1] = 'images/hdr_purple.jpg';
    pic[2] = 'images/hdr_yellow.jpg';
    pic[3] = 'images/hdr_blue.jpg';
    randomNum = Math.floor(Math.random()*pic.length);
    newImage = pic[randomNum];
    }

    // -->
    </script>

    And this goes in place of the BODY tag:

    <script language="JavaScript" type="text/javascript">
    randomImage();
    document.write('<body background="' + newImage + '">')
    </script>

    Keep in mind that if a user does not have JS enabled then your page may break. When working with the BODY tag, it would be best to use a server side language such as Perl, PHP or ASP for this purpose.
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  3. #3
    Say WHA?! goober's Avatar
    Join Date
    Sep 2000
    Location
    United States
    Posts
    1,921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ASP, anyone?

    I can show you how to do it in ASP if you'd like.
    Sean Killeen [LinkedIn] [Twitter] [Web]

    Warning: Reality.sys corrupted. Universe halted. Reboot? (Y/N)

  4. #4
    SitePoint Addict djh's Avatar
    Join Date
    Apr 2000
    Location
    Long Beach, CA
    Posts
    333
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey goober,

    i think the code to change the tag is pretty easy, but how do you randomize which image is selected?

    Yeah, if you can show it to me, I'd appreciate it!

  5. #5
    Say WHA?! goober's Avatar
    Join Date
    Sep 2000
    Location
    United States
    Posts
    1,921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://www.asp101.com/samples/downlo...%5Fimage%2Easp for the randomizing thing...may be jus what you're looking for.

    If not, I'll explain it myself.

    Hope this helps!
    Sean Killeen [LinkedIn] [Twitter] [Web]

    Warning: Reality.sys corrupted. Universe halted. Reboot? (Y/N)


Bookmarks

Posting Permissions

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