phreak7t7
asked on
Random rolling images with image specific links
Hi all,
Easiest way to describe this is to think of it as displaying ads on a page.
I need to be able to randomly display 2 images with thier specific links (the links will always be the same for any given image.
At the moment I have:
<script language="JavaScript">
var theImages1 = new Array() // do not change this
theImages1[0] = 'http://www.mydomain.com/common/images/rand01.gif'
theImages1[1] = 'http://www.mydomain.com/common/images/rand02.gif'
var j = 0
var p = theImages1.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
preBuffer[i] = new Image()
preBuffer[i].src = theImages1[i]
}
var whichImage = Math.round(Math.random()*( p-1));
function showImage1(){
document.write('<img src="'+theImages1[whichIma ge]+'">');
}
</script>
Which is ok but doesn't do any linking and in order to make sure the same image is not displayed twice I have to do two lots of the above with independant 'image lists' e.g.
<script language="JavaScript">
var theImages1 = new Array() // do not change this
theImages1[0] = 'http://www.mydomain.com/common/images/rand01.gif'
theImages1[1] = 'http://www.mydomain.com/common/images/rand02.gif'
var j = 0
var p = theImages1.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
preBuffer[i] = new Image()
preBuffer[i].src = theImages1[i]
}
var whichImage = Math.round(Math.random()*( p-1));
function showImage1(){
document.write('<img src="'+theImages1[whichIma ge]+'">');
}
</script>
<script language="JavaScript">
var theImages2 = new Array() // do not change this
theImages2[0] = 'http://www.mydomain.com/common/images/rand03.gif'
theImages2[1] = 'http://www.mydomain.com/common/images/rand04.gif'
var j = 0
var p = theImages2.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
preBuffer[i] = new Image()
preBuffer[i].src = theImages2[i]
}
var whichImage = Math.round(Math.random()*( p-1));
function showImage2(){
document.write('<img src="'+theImages2[whichIma ge]+'">');
}
</script>
An all in one solution is desired.. cheers in advance.
Easiest way to describe this is to think of it as displaying ads on a page.
I need to be able to randomly display 2 images with thier specific links (the links will always be the same for any given image.
At the moment I have:
<script language="JavaScript">
var theImages1 = new Array() // do not change this
theImages1[0] = 'http://www.mydomain.com/common/images/rand01.gif'
theImages1[1] = 'http://www.mydomain.com/common/images/rand02.gif'
var j = 0
var p = theImages1.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
preBuffer[i] = new Image()
preBuffer[i].src = theImages1[i]
}
var whichImage = Math.round(Math.random()*(
function showImage1(){
document.write('<img src="'+theImages1[whichIma
}
</script>
Which is ok but doesn't do any linking and in order to make sure the same image is not displayed twice I have to do two lots of the above with independant 'image lists' e.g.
<script language="JavaScript">
var theImages1 = new Array() // do not change this
theImages1[0] = 'http://www.mydomain.com/common/images/rand01.gif'
theImages1[1] = 'http://www.mydomain.com/common/images/rand02.gif'
var j = 0
var p = theImages1.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
preBuffer[i] = new Image()
preBuffer[i].src = theImages1[i]
}
var whichImage = Math.round(Math.random()*(
function showImage1(){
document.write('<img src="'+theImages1[whichIma
}
</script>
<script language="JavaScript">
var theImages2 = new Array() // do not change this
theImages2[0] = 'http://www.mydomain.com/common/images/rand03.gif'
theImages2[1] = 'http://www.mydomain.com/common/images/rand04.gif'
var j = 0
var p = theImages2.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
preBuffer[i] = new Image()
preBuffer[i].src = theImages2[i]
}
var whichImage = Math.round(Math.random()*(
function showImage2(){
document.write('<img src="'+theImages2[whichIma
}
</script>
An all in one solution is desired.. cheers in advance.
and you can remove the
var preBuffer = new Array()
for (i = 0; i < p; i++){
preBuffer[i] = new Image()
preBuffer[i].src = theImages[i]
}
or move it after the calculation so you can just prebuffer the chosen images
var preBuffer = new Array()
for (i = 0; i < p; i++){
preBuffer[i] = new Image()
preBuffer[i].src = theImages[i]
}
or move it after the calculation so you can just prebuffer the chosen images
ASKER
The bonus question :o) : is it possible to make the images with links randomly change in page say every 5 seconds as an example as apposed to just when the page loads?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Any reason for the "B" grade???
var theImages = new Array() // do not change this
var theLinks = new Array() // do not change this
theImages[0] = 'http://www.mydomain.com/common/images/rand01.gif'
theImages[1] = 'http://www.mydomain.com/common/images/rand02.gif'
theImages[2] = 'http://www.mydomain.com/common/images/rand03.gif'
theImages[3] = 'http://www.mydomain.com/common/images/rand04.gif'
theLinks[0] = 'http://www.mydomain.com/common/images/rand01.html'
theLinks[1] = 'http://www.mydomain.com/common/images/rand02.html'
theLinks[2] = 'http://www.mydomain.com/common/images/rand03.html'
theLinks[3] = 'http://www.mydomain.com/common/images/rand04.html'
var j = 0
var p = theImages.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
preBuffer[i] = new Image()
preBuffer[i].src = theImages[i]
}
var whichImage1 = Math.round(Math.random()*(
var whichImage2 = whichImage1;
while (whichImage2 == whichImage1) {
whichImage2 = Math.round(Math.random()*(
}
document.write('<a href="'+theLinks[whichImag
document.write('<a href="'+theLinks[whichImag
</script>