Results 1 to 6 of 6

Thread: How To Load Random Pictures in a Cell as Image OR Background From A Directory

  1. #1

    Thread Starter
    Addicted Member chockku's Avatar
    Join Date
    Sep 2003
    Posts
    174

    Question How To Load Random Pictures in a Cell as Image OR Background From A Directory

    Hi,

    If Any One Can give some script to change the background picture or image inside a cell for every 10 seconds randomly, If you can kindly send me. It will be more helpful

    Thankyou,
    Chock.
    HAVE A NICE DAY

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: How To Load Random Pictures in a Cell as Image OR Background From A Directory

    you need to supply a list of possible pictures from the server folder, as you cannot peruse a folders contents on the client side.

    Code:
    var imageElement;
    window.onload = init;
    
    // assuming 'images' is an array containing the address of each image
    
    function init()
    {
      imageElement = document.getElementById('image');
      setInterval('changeImage', 10000);
    }
    
    var prevImageID = -1;
    
    function changeImage()
    {
      do {
        var imageID = Math.round(Math.random() * images.length);
      } while (imageID != prevImageID);
      imageElement.style.background = "url('" + images[imageID] + "')";
      prevImageID = imageID;
    }
    The element whose background image is to be changed should have the ID "image". If you want to use a class name or tag name you will have to modify the code slightly to use an array of elements instead.

  3. #3

    Thread Starter
    Addicted Member chockku's Avatar
    Join Date
    Sep 2003
    Posts
    174

    Re: How To Load Random Pictures in a Cell as Image OR Background From A Directory

    Hi penagate,

    Thank you for your reply. ForYourInformation I am designing this page in FrontPage and saving it as Html. I think i have to add your code in the top of the page. Should i call the 'var imageElement' inside the table's Cell like this <td imageElement> or what. i am now displaying the background picture as below

    <img border="0" src="SAPSD%20Files/modImage-105.jpg" width="250" height="174">

    At the same time i seen in a site, they are displaying the pictures in a cell from different direction, from right to left, left to right, top to bottom vice versa & diagnolly. But when i save that page & see, there's a object where a file name 05.swf is diplayed in the cell where it displays random picutres, i right click & cheked it property it shows "Movie In Flash Format Properties"

    Kindly suggest how to use & code.

    Thankyou,
    Chock.
    HAVE A NICE DAY

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: How To Load Random Pictures in a Cell as Image OR Background From A Directory

    The code needs to go in a <script> element within the <head> section. As follows.

    HTML Code:
    <head>
      <!-- anything else you may have here ... -->
      <script type="text/javascript">
        var imageElement;
        window.onload = init;
    
        // assuming 'images' is an array containing the address of each image
    
        function init()
        {
          imageElement = document.getElementById('image');
          setInterval('changeImage', 10000);
        }
    
        var prevImageID = -1;
    
        function changeImage()
        {
          do {
            var imageID = Math.round(Math.random() * images.length);
          } while (imageID != prevImageID);
          imageElement.style.background = "url('" + images[imageID] + "')";
          prevImageID = imageID;
        }
      </script>
    </head>
    For it to work, you will need an element onthe page with the id "image", this is the element whos background image willbe changed randomly. Also you will need to supply a list of possible image addresses in the form of a Javascript array called "images".

  5. #5

    Thread Starter
    Addicted Member chockku's Avatar
    Join Date
    Sep 2003
    Posts
    174

    Re: How To Load Random Pictures in a Cell as Image OR Background From A Directory

    Hi,

    Thankyou for your replies. I will try this in my home, and come back to your on Saturday, because here its leave tommorrow. I hope i can resolve with your script.

    Thankyou,
    Chock.
    HAVE A NICE DAY

  6. #6

    Thread Starter
    Addicted Member chockku's Avatar
    Join Date
    Sep 2003
    Posts
    174

    Re: How To Load Random Pictures in a Cell as Image OR Background From A Directory

    Hi,

    I tried with your same code. But still strucked to display the image. I have attached the html page which is designed in FrontPage named Index1.html & all 3 jpeg files which i am trying to display randomly.Kindly can u check & correct where the mistakes is happen. If possible do the correction and send me. Strucked up with this for a long time. I written the function. I think the problem is when displaying the image only. For my code it didn't display any messages. If i give the input statemetn inside the <TD> then its showing a blank image. Need Your Help (.|.)

    Thankyou,
    Chock.
    Attached Files Attached Files
    Last edited by chockku; Mar 4th, 2006 at 04:53 AM. Reason: Insert the name of the Html Page
    HAVE A NICE DAY

Posting Permissions

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



Click Here to Expand Forum to Full Width