Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Sep 2012
    Posts
    47
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Need help with modifying this code:

    This code works for me except instead of a random image upon page reload... is there a way to modify this so it just does a random image about every 5 seconds? To be honest I don't really even need it to be random, if it can just play a list of images in order that works too.

    Code:
    <script type="text/javascript">
    <!--
     var imlocation = "RotatingImages/";
     var currentdate = 0;
     var image_number = 0;
     function ImageArray (n) {
       this.length = n;
       for (var i =1; i <= n; i++) {
         this[i] = ' '
       }
     }
     image = new ImageArray(3)
     image[0] = '1.jpg'
     image[1] = '2.jpg'
     image[2] = '3.jpg'
     var rand = 60/image.length
     function randomimage() {
     	currentdate = new Date()
     	image_number = currentdate.getSeconds()
     	image_number = Math.floor(image_number/rand)
     	return(image[image_number])
     }
     document.write("<img src='" + imlocation + randomimage()+ "'>");
    //-->
    </script>

  2. #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    17,027
    Thanks
    4
    Thanked 2,668 Times in 2,637 Posts
    Despite the similar sounding names, Java is not the same as Javascript.
    Moving from Java forum to Javascript forum.

  3. #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    29,698
    Thanks
    93
    Thanked 4,947 Times in 4,908 Posts
    We could write a custom answer for you, but what you are after is known as a "slideshow" or sometimes (inaccurately) as a "lightbox". There are *TONS* of scripts out there for all kinds of slideshows. Just google for "javascript slide show" and be prepared to be inundated.
    Be yourself. No one else is as qualified.

  4. Users who have thanked Old Pedant for this post:

    themoon (01-10-2013)


 

Posting Permissions

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