Results 1 to 2 of 2

Thread: How do I do a random image script?

  1. #1

    Thread Starter
    Addicted Member ddmeightball's Avatar
    Join Date
    Nov 2004
    Location
    Nebraska
    Posts
    183

    How do I do a random image script?

    What I want it a random image script made in Javascript. It needs to change every 5 seconds with a different image. That would be a setInterval(); method, but how would I cache the images and put all this on a web page?

  2. #2
    Junior Member
    Join Date
    Oct 2004
    Posts
    23

    Re: How do I do a random image script?

    you can test with the following code
    it can be further modified by preloading images

    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <script language = "javascript">
    var i
    i = 7
    function f()
    {
    if(i > 12)
    {
    i = 7
    }
    document.getElementById("IM").src = "http://www.vbforums.com/images/icons/icon" + i + ".gif";
    i++
    }
    </script>
    </HEAD>

    <BODY>
    <img src = "http://www.vbforums.com/images/icons/icon12.gif" id = "IM">
    <br>
    <input type = "button" name = "b1" value = "Change" onClick = "f();">
    </BODY>

    </HTML>

    Quote Originally Posted by ddmeightball
    What I want it a random image script made in Javascript. It needs to change every 5 seconds with a different image. That would be a setInterval(); method, but how would I cache the images and put all this on a web page?

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