Anyone have an idea on how to cycle images (backgrounds)

Discussion in 'CSS' started by itzCarlin, Oct 27, 2007.

  1. #1
    Hey, I need some help with CSS.

    I would like to be able to cycle images through CSS to keep visitors "on their toes" with an everchanging background. I have multiple .jpg backgrounds that I would just like for it to cycle or be random.
     
    itzCarlin, Oct 27, 2007 IP
  2. js09

    js09 Peon

    Messages:
    232
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    use a PHP image rotate script maybe
     
    js09, Oct 27, 2007 IP
  3. soulscratch

    soulscratch Well-Known Member

    Messages:
    964
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    155
    #3
    A couple methods I can think of using PHP..

    1. Randomly assigning an ID or CLASS to the element that you want to have a different background...

    $foo = rand(1, 5);
    <body class="<?php echo 'section-' . $foo; ?>">

    And in your CSS

    body.section-1 { background-image:url(1.jpg) no-repeat; }
    body.section-2 { background-image:url(2.jpg) no-repeat; }

    2. Making your stylesheet PHP itself.. with content-type of text/css, and having an array inside with the images that you need

    $images = array ('foo.jpg', 'bar.jpg', 'moo.jpg');

    div#wrapper { background-image:url( <?php echo array_rand($images); ?> ) }

    Although you might have some problems getting this PHP stylesheet to cache.

    3. Linking to a PHP page that randomly outputs images IN the CSS.

    background-image:url(foo.php) where foo.php has a content-type of image/jpeg or whatever the randomly generated image's mime type is

    Although, I have never tried methods #2 and #3 myself.. I would probably recommend the first method since its the easiest.
     
    soulscratch, Oct 27, 2007 IP
  4. qube99

    qube99 Peon

    Messages:
    75
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Or do it the easy way - animated GIF with a slow frame rate.
     
    qube99, Oct 28, 2007 IP
  5. soulscratch

    soulscratch Well-Known Member

    Messages:
    964
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    155
    #5
    I have multiple .jpg backgrounds
     
    soulscratch, Oct 28, 2007 IP