dimanche 22 février 2015

how to make javascript random image with hyperlink with array

i want to make random image with link, but i didnt understand. anyone can help me?


this is the javascript in header



<script type="text/javascript">
var random_images_array = ['banner/headline/chrome.png','banner/headline/thunderbird.png','banner/headline/vlc.png'];
var random_details_array = ['http://ift.tt/m5a6y3','http://ift.tt/1luW7eO','http://ift.tt/KKdZ2l'];

function getRandomImage(imgAr, path) {
path = path || 'images/';

var num = Math.floor( Math.random() * imgAr.length );
var img = imgAr[ num ];
var lnk = imgAr[ num ];
var imgStr = '<a href="'+ lnk +'"><img src="' + path + img + '" alt="" class="img-responsive"></a>';

document.write(imgStr); document.close();
}
</script>


this is the javascript in body



<script type="text/javascript">
getRandomImage(random_images_array, 'images/')
</script>




Aucun commentaire:

Enregistrer un commentaire