Hi there. Having trouble finding this on Google, but I would like to know how to have 2 or more images (or any object,) but only display one at a time at random. For example, if I were to go to a site with this feature, I would see "image1.jpg" but if I were to reload, I might see "image2.jpg" or "image3.jpg" at random. Thanks for any help.
Randomize image display - JavaScript help
Started by egon, Oct 08 2006 10:55 PM
1 reply to this topic
#1
Posted 08 October 2006 - 10:55 PM
|
|
|
#2
Posted 09 October 2006 - 06:13 AM
So you just want a random generator to display your images? Using Javascript?
<script language="Javascript">
<!--
// please keep these lines on when you copy the source
// made by: Nicolas - http://www.javascript-page.com
var currentdate = 0
var core = 0
function StringArray (n) {
this.length = n;
for (var i =1; i <= n; i++) {
this[i] = ' '
}
}
image = new StringArray(10)
image[0] = '0.gif'
image[1] = '1.gif'
image[2] = '2.gif'
image[3] = '3.gif'
image[4] = '4.gif'
image[5] = '5.gif'
image[6] = '6.gif'
image[7] = '7.gif'
image[8] = '8.gif'
image[9] = '9.gif'
var ran = 60/image.length
function ranimage() {
currentdate = new Date()
core = currentdate.getSeconds()
core = Math.floor(core/ran)
return(image[core])
}
document.write("<img src='" +ranimage()+ "'>")
//-->
</script>


Sign In
Create Account


Back to top









