CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   Need help with modifying this code: (http://www.codingforums.com/showthread.php?t=285579)

themoon 01-10-2013 07:54 PM

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>


Fou-Lu 01-10-2013 08:11 PM

Despite the similar sounding names, Java is not the same as Javascript.
Moving from Java forum to Javascript forum.

Old Pedant 01-10-2013 08:36 PM

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.


All times are GMT +1. The time now is 02:32 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.