It's almost there! If you had animations, you would have to change some of what you already have, but since (at least for now) you do not have to change your conditions to change the var current
and add a else
.
When you want to slide right, you'll see if you're already on the last slide, and if you are, you'll be redirecting to the first current = 0
. When you do to the left, it is the opposite check, if you are on the first slide, you send the last, current = sliderImages.length - 1
(-1 because the array has index 0).
Stay like this.
//Mostrar anterior
function slideLeft() {
reset();
if (current > 0) { // aqui fica igual
current--;
} else { // mas caso current seja 0, entao é o primeiro slide, temos de mandar para o último
current = sliderImages.length - 1;
}
sliderImages[current].style.display = "block";
}
// Mostrar seguinte
function slideRight() {
reset();
if (current < sliderImages.length - 1) { // aqui temos de adicionar o -1 para comparar que current é 3 (posicao do ultimo slide no array)
current++;
} else { // e adicionamos o else para mandar para o primeiro
current = 0;
}
sliderImages[current].style.display = "block";
}