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

253
Visualizações
Autoplay in slider with js

let left = document.querySelector('.left');
let right = document.querySelector('.right');
let img = document.querySelector('.imgs');
let imgs = document.querySelectorAll('img');

let index = 0;


function rightimg() {
  right.addEventListener('click', function () {
    index++;
    if (index > imgs.length - 1) {
      index = 0;
    }
    img.style.transform = `translateX(${-index * 500}px)`;
    console.log(img);
  });
}

// setInterval(rightimg, 2000);

left.addEventListener('click', function () {
  index--;
  if (index < 0) {
    index = imgs.length - 1;
  }
  img.style.transform = `translateX(${-index * 500}px)`;
  console.log(img);
});
Hi friends, I want to make autoplay image in this slider but setInterval is not working, can you say what is wrong in here? Thank you

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Your function adds an eventlistener but it will only work when there will be an event(which is click in this case)

You can use swiperjs, it has many types of features and framework/library implentations. https://swiperjs.com/swiper-api

about 4 years ago · Juan Pablo Isaza Relatório
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