Javascript - Simple Slideshow


SUBMITTED BY: Guest

DATE: Aug. 6, 2013, 9:55 p.m.

FORMAT: JavaScript

SIZE: 1.4 kB

HITS: 2137

  1. <!DOCTYPE html>
  2. <html >
  3. <head>
  4. <title></title>
  5. <script>
  6. function rotate(imageNumber) {
  7. var myimage = new Array;
  8. //Modify these variables as needed
  9. //vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  10. myimage.push("image1.jpg");
  11. myimage.push("image2.jpg"); //Add additional
  12. myimage.push("image3.jpg"); //myimage.push()
  13. myimage.push("image4.jpg"); //for each image
  14. //myimage.push... etc.
  15. var time = 5000; //5000 milliseconds = 5 seconds
  16. //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  17. var image = document.getElementById('rotator');
  18. if (imageNumber < myimage.length) {
  19. image.src = myimage[imageNumber];
  20. imageNumber++;
  21. }
  22. else {
  23. imageNumber = 0;
  24. image.src = myimage[imageNumber];
  25. imageNumber++;
  26. }
  27. var t = setTimeout("rotate(" + imageNumber + ")", time);
  28. }
  29. </script>
  30. </head>
  31. <body onload="rotate(0);">
  32. <div>
  33. <img src="image1.jpg" id="rotator" />
  34. </div>
  35. </body>
  36. </html>

comments powered by Disqus