/ Published in: JavaScript

Place this script inside your <BODY> tag. Make sure to change the number of images, image directory and the file names in the array.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<script type="text/javascript"> // # of images var imgCount = 4; // image directory var dir = 'http://yourdomain.com/images/bg/'; // random the images var randomCount = Math.round(Math.random() * (imgCount - 1)) + 1; // array of images & file name var images = new Array images[1] = "1.jpg", images[2] = "2.jpg", images[3] = "3.jpg", images[4] = "4.jpg"; document.body.style.backgroundImage = "url(" + dir + images[randomCount] + ")"; </script>
URL: http://marioluevanos.com/playground/Random%20Background/
Comments
