ivapopova

HWcarouselSimple.html

Jun 3rd, 2018
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.09 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>carouselSimple</title>
  6.     <link rel="stylesheet" type="text/css" href="carouselSimple.css">
  7. </head>
  8. <body>
  9.     <img src="" style="height: 5em">
  10.     <button onclick="nextImage()">Next Image</button>
  11. </body>
  12. <script type="text/javascript">
  13.     # get image node:
  14.     var imgNode =  document.querySelector("img");
  15.  
  16.  
  17.     var imgURLs = [
  18.         "http://imageshack.com/a/img922/3858/5Pd5dc.jpg",
  19.         "http://imageshack.com/a/img923/3776/lKVbAp.jpg",
  20.         "http://imageshack.com/a/img923/6770/WXkPF9.jpg",
  21.         "http://imageshack.com/a/img923/2200/SzDjvi.jpg",
  22.         "http://imageshack.com/a/img924/8715/tz0p3T.jpg",
  23.     ];
  24.  
  25.     // set img src with first imgURLs
  26.     imgNode.setAttribute("src", imgURLs[0]);
  27.  
  28.  
  29.     // set next image url to "src" attribute
  30.     var i = 0;
  31.     function nextImage(){
  32.         imgNode.setAttribute("src", imgURLs[i]);
  33.  
  34.         //TASK1: make i to start from 0, after the last URL is used:
  35.         i = i +1;
  36.     }
  37.  
  38.     // TASK 2:
  39.     // implement prevImage() function, which will set the previous image url to "src" attribute
  40.  
  41. </script>
  42. </html>
Advertisement
Add Comment
Please, Sign In to add comment