Random Image Script


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.