Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Name: randomImage.js
  2.  * Description: JavaScript code for choosing a random image from a designated set.
  3.  * Copyright: None, Public domain.
  4.  */
  5.  
  6. var imageFiles = new Array() // Set up the array that will hold the image files
  7. // Modify the following to suit your needs.
  8. imageFiles[0] = 'example.1'
  9. imageFiles[1] = 'example.2'
  10. imageFiles[2] = 'example.3'
  11. imageFiles[3] = 'example.4'
  12.  
  13. // End modification
  14.  
  15. // There is no need to modify anything after this.
  16.  
  17. var counter = imageFiles.length;
  18. var preBuffer = new Array()
  19.  
  20. for (i = 0; i < counter; i++)
  21. {
  22.    preBuffer[i] = new Image()
  23.    preBuffer[i].src = imageFiles[i]
  24. }
  25.  
  26. var whichImage = Math.round(Math.random() * (counter-1));
  27.  
  28. function showImage()
  29. {
  30.     // This code should be modified to suit your needs. Change and/or remove the height, width and alt tags.
  31.     document.write('<img src="'+imageFiles[whichImage]+' height="change this" width="change this" alt="Change this"">');
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement