...

View Full Version : Rotating a photo with each reload



harvey
09-27-2005, 03:07 AM
I am trying to set up a web page that will load a different photo into the same space with each reload. This will show a different look each time a visitor goes to the site.
Help! I have seen the code before, but naturally, when I need it....can't find it.

Thanks for your help!!

Vladdy
09-27-2005, 04:21 AM
a) Best done on the server side so that users with JS disabled can enjoy that functionality.
b) STFW (or to put it mildly GIYF)
c) I feel altruistic today :thumbsup:


...
<script type="text/javascript">
photos = ['photo1.jpg','photo2.jpg','photo3.jpg'];
function replacePhoto()
{ document.getElementById('randomImage').src = photos[Math.floor(.99*Math.random()*photos.length)];
}
</script>
</head>
<body onload="replacePhoto()">
...
<img id="randomImage" alt="My image" src="photo0.jpg" />
...

harvey
10-01-2005, 05:25 AM
Thanks!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum