Results 1 to 2 of 2

Thread: Random Background Image

  1. #1
    Join Date
    May 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Random Background Image

    I have nine images that I'd like to assign as random background images in a table.

    Can anybody help with that?

    Thanks!

  2. #2
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    This uses a random number, and an array of images to show a random background color for a table.

    Code:
    <html>
    <head>
    <script type="text/javascript">
    var images = new Array("image1.jpg","image2.jpg","image3.jpg","image4.jpg","image5.jpg","image6.jpg","image7.jpg","image8.jpg","image9.jpg")
    onload=function() {
    var rand = Math.round(Math.random()*images.length-1)
    table1.style.background="url('"+images[rand]+"')"
    }
    </script>
    </head>
    <body>
    <table id="table1"></table>
    </body>
    </html>
    - Mike

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
  •