Back to start slide JS

1

Good morning! From now on I apologize for the title but I do not find any better ...
Well I have a page that displays the contents in " Slide ", ie start shows the slide 1, and press the next arrow shows the next ( slide 2). Home To let see clearer here - link (expand the square result)
. What I meant now is that after spending the last slide, instead of getting one blank page, return to 1 slide , I experimented with while % % s but I could not deploy ...
Thank you to anyone who can help!

    
asked by anonymous 04.07.2018 / 12:20

1 answer

1

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";
}
    
04.07.2018 / 12:37