Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Name: randomImage.js
- * Description: JavaScript code for choosing a random image from a designated set.
- * Copyright: None, Public domain.
- */
- var imageFiles = new Array() // Set up the array that will hold the image files
- // Modify the following to suit your needs.
- imageFiles[0] = 'example.1'
- imageFiles[1] = 'example.2'
- imageFiles[2] = 'example.3'
- imageFiles[3] = 'example.4'
- // End modification
- // There is no need to modify anything after this.
- var counter = imageFiles.length;
- var preBuffer = new Array()
- for (i = 0; i < counter; i++)
- {
- preBuffer[i] = new Image()
- preBuffer[i].src = imageFiles[i]
- }
- var whichImage = Math.round(Math.random() * (counter-1));
- function showImage()
- {
- // This code should be modified to suit your needs. Change and/or remove the height, width and alt tags.
- document.write('<img src="'+imageFiles[whichImage]+' height="change this" width="change this" alt="Change this"">');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement