Mutliple random images with 'personal' links
Hello all,
I've been searching the net for a while, for the easiest multiple random images code and found it. But now I've also been searching for a script to link all single images to a different link (link z1.jpg to home.html, z2.jpg to contact.html, x1 to banana.html, etc.).
This is the script I'm using:
Code:
<script language="javascript">
<!--
var gallery = new Array();
gallery[0] = new Array("z1.jpg","z2.jpg","z3.jpg","z4.jpg","z5.jpg");
gallery[1] = new Array("y1.jpg","y2.jpg","y3.jpg","y4.jpg","y5.jpg");
gallery[2] = new Array("x1.jpg","x2.jpg","x3.jpg","x4.jpg","x5.jpg", "x6.jpg");
gallery[3] = new Array("w1.jpg","w2.jpg","w3.jpg","w4.jpg","w5.jpg");
gallery[4] = new Array("v1.jpg","v2.jpg","v3.jpg","v4.jpg","v5.jpg");
function pickImageFrom(whichGallery)
{
var idx = Math.floor(Math.random() * gallery[whichGallery].length);
document.write('<img src="images/' + gallery[whichGallery][idx] + '">');
}
//-->
</script>
This is what i place in where the image schould be placed:
Code:
<script language="javascript">pickImageFrom(0);</script>
Please help!
Thanks!
Don't quite understand the problem ... works fine for me!
Quote:
Originally Posted by
Stronk
Thanks a lot! I got this working.
But the problem is I need more random images, now I've got only one,...
Thanks!
You're most welcome.
Happy to help.
Good Luck!
BTW: Why the problem? What do you mean that you "need more random images"?
Problems with the script or problems obtaining images to display?
Don't quite understand the problem ... works fine for me!
What code are you using? :confused:
Did you try to execute the code of post #2? :eek:
Substitute your information (which you have not provided) into this array:
Code:
var imgLinks = [
// format: ['imageSource','imageLinkURL'],
['z1.jpg','home.html'],
... continue with your assignments per format above ...
['z2.jpg','about.html'] // NOTE: no comma after last entry
];
Please explain what problems you are having ... I don't understand. :o