It’s almost over there! If you had animations, you would have to change a little what you already have, but, as (at least for now) you don’t, just change your conditions that change to var current
and add a else
.
When you want to slide right, check if you are already on the last slide, and if you are, send it back to the first one current = 0
. When you do it left, it’s the opposite check, if you’re on the first slide, send it to the last, current = sliderImages.length - 1
(-1 because the array has Indice 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";
}
Perfect!! Thank you very much, after all it was so simple, and I complicated everything, even though I tried it that way, but I couldn’t because it didn’t cross my mind
-1
in functionslideRight()
, then I assumed it wouldn’t work! Thank you very much!!– Ana