/ Published in: JavaScript

Usage example:
randomImage(['0.gif',50,50,'1.gif',25,25,'2.gif',50,25]);
randomImage(['0.gif',50,50,'1.gif',25,25,'2.gif',50,25]);
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function randomImage(imgArr) { var imgSrc, imgW, imgH, r; r = Math.floor(Math.random()*(imgArr.length / 3))-1; imgSrc = imgArr[r * 3]; imgW = imgArr[(r * 3)+1]; imgH = imgArr[(r * 3)+2]; document.write('<IMG SRC='+imgSrc+' WIDTH='+imgW+' HEIGHT='+imgH+'>'); }
Comments
