Posted By

hellofromdan on 12/07/09


Tagged

random


Versions (?)

Random Image Script


 / Published in: JavaScript
 

URL: http://www.jsCode.com/

  1. // Set up the image files to be used.
  2. var theImages = new Array() // do not change this
  3. // To add more image files, continue with the
  4. // pattern below, adding to the array. Rememeber
  5. // to increment the theImages[x] index!
  6.  
  7. theImages[0] = 'IMG_2058.JPG'
  8. theImages[1] = 'IMG_2327.JPG'
  9. theImages[2] = 'IMG_2347.JPG'
  10. theImages[3] = 'IMG_2390.JPG'
  11. theImages[4] = 'IMG_2417.JPG'
  12. theImages[5] = 'IMG_3930.JPG'
  13. theImages[6] = 'IMG_3761.JPG'
  14.  
  15.  
  16. // ======================================
  17. // do not change anything below this line
  18. // ======================================
  19.  
  20. var j = 0
  21. var p = theImages.length;
  22.  
  23. var preBuffer = new Array()
  24. for (i = 0; i < p; i++){
  25. preBuffer[i] = new Image()
  26. preBuffer[i].src = theImages[i]
  27. }
  28.  
  29. var whichImage = Math.round(Math.random()*(p-1));
  30. function showImage(){
  31. document.write('<img src="'+theImages[whichImage]+'">');
  32. }

Report this snippet  

You need to login to post a comment.