SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2000
    Location
    CT
    Posts
    160
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Random image script

    Hi everyone,

    I am designing a site for a friend and he wants the homepage to have an different image (out of say 5) appear when the site is loaded. This might sound confusing... but he does not want an image rotator, he simply wants a different one of the 5 pics to appear when the site is loaded.

    Thanks in advance.

    Steve

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <html>
    <head>
    <title>Test</title>
    
    <script>
    var rootPath = "/images/homepage/"; // Or wherever
    var arrImages = ('pic1.jpg','pic2.jpg','pic3.jpg','pic4.jpg','pic5.jpg');
    </script>
    </head>
    
    <body>
    
    <script>
    var rand = Math.floor(Math.random() * arrImages.length);
    document.write('<img src="' + rootPath +''+ arrImages[rand] + '" />');
    </script>
    
    </body>
    </html>
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev





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
  •