Find answers, ask questions, and connect with our
community around the world.

Forums Forums Web Design Question about a JS clickable slideshow

  • Question about a JS clickable slideshow

    updated 1 year, 9 months ago 0 Member · 1 Post
  • BusinessMag

    Member
    December 8, 2020 at 11:36 pm

    hey guys, below I’ve supplied my code and I am having an issue. I am trying to make a clickable slideshow with two buttons that allow a user to move forward to the next image or backward to the previous one. Everything works fine for the most part but whenever I go from clicking the forward button to the backward button, the backward button moves forward one time and then goes backward. Is there an issue with the functions? my code: <script> var i = 0; var images = []; var time = 4200; images[0] = ’13_reasons.jpg’; images[1] = ’50_shades.jpg’; images[2] = ‘captain_underpants.jpg’; images[3] = ‘harry_potter.jpg’; images[4] = ‘huckleberry_finn.jpg’; images[5] = ‘kite_runner.jpg’; images[6] = ‘looking_alaska.jpg’; images[7] = ‘mice_men.jpg’; images[8] = ‘wall_flower.jpg’; /*function changeImg() { document.slideshow.src = images[i]; if(i < images.length – 1){ i++; } else { i = 0; } setTimeout(“changeImg()”, time); }*/ window.onload = changeImg; function forward() { document.slideshow.src = images[i]; if(i < images.length – 1){ i++; } else { i = 0; } } function backward() { document.slideshow.src = images[i]; if(i > 0) { i–; } else { i = 8; } } </script> <body> <img name = “slideshow” width = “338.82px” height = “520.935px”><br> <button onclick=”backward()”>previous</button> <button onclick=”forward()”>next</button> </body>
    – by /hq/yaboifro53 – –

Viewing 1 of 1 replies
Reply to: BusinessMag
Your information:

Cancel
Original Post
0 of 0 posts June 2018
Now