lundi 19 décembre 2016

Multiply Random Image Display with link

i have a question. i need a code to show 4 random pictures with link. the code i have works, but there is one problem.

i show the pictures with ran, ran+1, ran+2, ran+3

now, when the first picture for example is random 4, the following pictures will be 5, 6 and 7

but when i have just 6 pictures the last will be show as an error.

hopefully u understand what i mean, i am from geramy ;)

the code i use at the moment:

<script language="JavaScript" type="text/javascript"> 
<!-- 
var image = new Array(); 
var link = new Array(); 
/** Hier die (Zufalls)-Bilder eintragen. **/ 
image[1] = 'bild1.jpg'; 
image[2] = 'bild2.jpg'; 
image[3] = 'bild3.jpg'; 
image[4] = 'bild4.jpg';

/** Hier die (Zufalls)-Links eintragen. **/ 
link[1] = 'link1'; 
link[2] = 'link2'; 
link[3] = 'link3'; 
link[4] = 'link4'; 

/** Ab hier nichts mehr ändern! **/ 
var num = Math.random(); 
var ran = Math.floor((image.length - 1) * num) + 1; 

document.write('<a href="' + link[ran] + '"><img src="' + image[ran] + '" border="0" / width="20%" style="border-radius:10px; border:1px solid #212121;margin:5px;"></a>'); 

document.write('<a href="' + link[ran+1] + '"><img src="' + image[ran+1] + '" border="0" / width="20%" style="border-radius:10px; border:1px solid #212121;margin:5px;"></a>'); 

document.write('<a href="' + link[ran+2] + '"><img src="' + image[ran+2] + '" border="0" / width="20%" style="border-radius:10px; border:1px solid #212121;margin:5px;"></a>'); 

document.write('<a href="' + link[ran+3] + '"><img src="' + image[ran+3] + '" border="0" / width="20%" style="border-radius:10px; border:1px solid #212121;margin:5px;"></a>');
//--> 
</script> 

so i need a code like if ran bigger than 6 use "-" not "+" is this possible?

would be very awesome if anyone knows an answer. :)

kind regards




Aucun commentaire:

Enregistrer un commentaire