Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

245
Visualizações
How to make a carousel to change slides after 3 items, javascript

I am trying to create a carousel with JavaScript for a WordPress website and i have made it work by showing 1 slide at a time with this code:

const slides = document.querySelectorAll(".slider-slide");

const prev = document.querySelector(".slider-arrows-left");
const next = document.querySelector(".slider-arrows-right");

let slideIndex = 0;
showSlide(slideIndex);

function showSlide() {
  if (slideIndex > slides.length - 1) {
    slideIndex = 0;
  }

  if (slideIndex < 0) {
    slideIndex = slides.length - 1;
  }

  let i;
  for (i = 0; i < slides.length; i++) {
    slides[i].style.display = "none";
  }
  slides[slideIndex].style.display = "block";
}

next.addEventListener("click", () => {
  showSlide((slideIndex += 1));
});

prev.addEventListener("click", () => {
  showSlide((slideIndex -= 1));
});

My question is how can i make the same carousel to constantly displays 3 slides and by pressing 'next' the first slide to become display="none" and the fourth to be display="block"?

And then, by pressing 'next' again, the second slide to become display="none" and the fifth to be display="block", then the third slide to become display="none" and the sixth to be display="block" e.t.c. until the end of the array?

Also to do it to go back with the 'prev' button?

I think its pretty simple, but i don't know how exactly to write the code... i am pretty new in coding..

Thank you

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda