-3

I have the found the following code

how does one go about adapting this code in the form of adding buttons to go forwards and backwards in the slideshow.

Community
  • 1
  • 1
Ben
  • 19
  • 1
  • 4
  • 2
    Welcome to Stack Overflow. We’d love to help you. To improve your chances of getting an answer, here are some tips: [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask) – Paul Roub Jul 22 '15 at 13:41

1 Answers1

0

Explaining:

Slide forward:

Make a button with the following onclick event

<button onclick="slideit()">forward</button>

If you don't want the slide to change every two and a halve seconds, just put this // before the line:

setTimeout("slideit()",2500);

or delete it.

Slide backward:

<button onclick="slideback()">back</button>

function for sliding backward:

var numSlides = ;

function slideback() {
   document.images.slide.src = eval("image"+step+".src");
   if (step > 1) {
      step--;
   }
   else {
      step=numSlides;
   }

}

You need to set numSlides to the number of slides you have.

Summary:

HTML:

<button onclick="slideback()">back</button>    
<button onclick="slideit()">forward</button>

Script:

var numSlides = ;
var autoplay= ;

function slideback() {
   document.images.slide.src = eval("image"+step+".src");
   if (step > 1) {
      step--;
   }
   else {
      step = numSlides;
   }

}

function slideit() {
   var step=1;
   document.images.slide.src = eval("image"+step+".src")
   if (step < numSlides) {
      step++
   }
   else {
      step = 1
   }
   if (autoplay == true) {
   setTimeout("slideit()",2500)
   }
}

Set autoplay to true/false for autoplay, set numSlides to your number of slides

LarsW
  • 1,514
  • 1
  • 13
  • 25