Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. <!DOCTYPE html>
  2.  
  3. <html>
  4. <head>
  5. <title>change picture</title>
  6. <script type = "text/javascript">
  7. function displayNextImage() {
  8. x = (x === images.length - 1) ? 0 : x + 1;
  9. document.getElementById("img").src = images[x];
  10. }
  11.  
  12. function displayPreviousImage() {
  13. x = (x <= 0) ? images.length - 1 : x - 1;
  14. document.getElementById("img").src = images[x];
  15. }
  16.  
  17. function startTimer() {
  18. setInterval(displayNextImage, 30000);
  19. }
  20.  
  21. var images = [], x = -1;
  22. images[0] = "image1.jpg";
  23. images[1] = "image2.jpg";
  24. images[2] = "image3.jpg";
  25. </script>
  26. </head>
  27.  
  28. <body onload = "startTimer()">
  29. <img id="img" src="startpicture.jpg"/>
  30. <button type="button" onclick="displayPreviousImage()">Previous</button>
  31. <button type="button" onclick="displayNextImage()">Next</button>
  32. </body>
  33. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement