Results 1 to 8 of 8

Thread: Random images in CSS

  1. #1
    Join Date
    Nov 2008
    Posts
    1,022

    Random images in CSS

    I am trying to edit and change a theme applied to a Coppermine gallery. I have some basic knowledge of HTML, but that's all.

    HTML Code:
    .header{ 
    background: url(images/headerbg.gif) no-repeat; 
    width: 760px; 
    height: 143px; 
    float: left; 
    }
    I want to replace the code so that the image is random. Here is the code:

    HTML Code:
    <? 
    $imgs = array("image1.gif", "image2.gif", "image3.gif"); 
    srand ((double)microtime()*1000000); 
    shuffle($imgs); 
    echo '<img src="repertoireimages/' . $imgs[0] . '" BORDER = "0" alt="" />'; 
    ?>
    The problem is that PHP, and this stylesheet has difficulty with the code. Someone have an idea to display a random image? Or even change the picture every day?

  2. #2
    Join Date
    May 2008
    Posts
    945

    Re: Random images in CSS

    Sorry mate but we can not do CSS dynamic. In your case, you can make CSS to set the format for this image against what will appear from the PHP

  3. #3
    Join Date
    May 2008
    Posts
    913

    Re: Random images in CSS

    Overload your style in your page header PHP directly into the tag.

    HTML Code:
    <? 
    $imgs = array("image1.gif", "image2.gif", "image3.gif"); 
    srand ((double)microtime()*1000000); 
    shuffle($imgs); 
    ?>
    
    ... 
    <div style="background: url(<?echo 'repertoireimages/' . $imgs[0]; ?>) no-repeat"> 
    ... 

  4. #4
    Join Date
    Nov 2008
    Posts
    1,022

    Re: Random images in CSS

    Well, I'll consider that, for all you say is to change the header of my Coppermine gallery. The image is placed by the CSS, hence my question.

  5. #5
    Join Date
    May 2008
    Posts
    913

    Re: Random images in CSS

    In fact, rather than putting the image via CSS, it must be placed directly on the page via a php style always.

    You want in your page .php tag that contains the words "class = header" and put in this tag

    HTML Code:
    class="header" style="background: url(<?echo 'repertoireimages/' . $imgs[0]; ?>) no-repeat">
    knowing a little higher on the page you wrote this script that will make a shuffle images on the table

  6. #6
    Join Date
    Nov 2008
    Posts
    1,022

    Re: Random images in CSS

    Well, I just turned but the different DIV bother me (not to the desired image in the background) and I am back on good old tables!

    Now it is impossible to eat my random image in the background of the table.

    HTML Code:
    <script language="JavaScript"> 
    banner(); 
    </SCRIPT>
    In the image field background of the table ... I see it "banner ();

    How?

  7. #7
    Join Date
    May 2008
    Posts
    913

    Re: Random images in CSS

    On your index.php add the following code:

    PHP Code:
    <?php 
    $imgs 
    = array("image1.gif""image2.gif""image3.gif"); 
    srand ((double)microtime()*1000000); 
    shuffle($imgs); 
    ?>
    then

    PHP Code:
    <script LANGUAGE="JavaScript"> 
    function changeFond() { 
    document.getElementById("maTableHeader").style.backgroundImage='url(<?php echo $imgs[0]?>)' 

    </script>
    then this:

    PHP Code:
    <body onload="changeFond()"
    and finally in the page where your table is described must be added

    PHP Code:
    <table width="860" height="143" id="maTableHeader"

  8. #8
    Join Date
    Nov 2008
    Posts
    1,022

    Re: Random images in CSS

    Hey perfect, thank you very much!

    I just go with this code without much understanding, hope it will help me!

Similar Threads

  1. Replies: 4
    Last Post: 13-01-2012, 05:07 PM
  2. How to add images to Google Images
    By Monty1 in forum Tips & Tweaks
    Replies: 2
    Last Post: 14-02-2011, 01:15 PM
  3. Replies: 3
    Last Post: 23-11-2010, 10:03 PM
  4. How to use "Math.random()" to generate a random number in JavaScript?
    By Silent~Kid in forum Software Development
    Replies: 5
    Last Post: 03-02-2010, 05:06 AM
  5. PHP Random image 3 images in a row
    By fastrod in forum Software Development
    Replies: 4
    Last Post: 09-03-2009, 01:40 PM

Tags for this Thread

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
  •  
Page generated in 1,751,668,713.02630 seconds with 16 queries