Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi
I currently have a list of 170 images

I want to have 20 images displayed on load and every time the page is refreshed another random 20 images will be displayed.
Posted

Hi,

Could you try the following code. Just have a look at the array of images here.
I am not sure if this is the exact thing you are looking for.

JavaScript
<script type="text/javascript">

 var imagelocation = "images/";
 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] = 'image1.gif'
 image[1] = 'image2.gif'
 image[2] = 'image3.gif'

 var rand = 60/image.length

 function GenerateRandomImage() {
 	currentdate = new Date()
 	image_number = currentdate.getSeconds()
 	image_number = Math.floor(image_number/rand)
 	return(image[image_number])
 }
 document.write("<img src="" + imagelocation + GenerateRandomImage()+ "">");

</script></img></script>


Also check this out :
http://www.robwalshonline.com/posts/jquery-plugin-random-image-on-page-load/[^]

and

http://stackoverflow.com/questions/6930749/running-random-pictures-in-asp-net-site[^]

Hope this helps!!

Regards,
Praneet
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900