Posted By

danielwrobert on 12/16/10


Tagged

javascript


Versions (?)

Displaying A Random Image


 / Published in: JavaScript
 

A nice little code snippet for displaying images randomly when a page is reloaded.

  1. window.onload = choosePic;
  2.  
  3. var myPix = new Array("images/00.jpg","images/01.jpg","images/02.jpg","images/03.jpg","images/04.jpg","images/05.jpg","images/06.jpg","images/07.jpg");
  4.  
  5. function choosePic() {
  6. randomNum = Math.floor((Math.random() * myPix.length));
  7. document.getElementById("myPicture").src = myPix[randomNum];
  8. }

Report this snippet  

You need to login to post a comment.