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

192
Visualizações
How to create an automatic gallery that goes fast, then stops on one image for longer

So I have an automatic gallery taken from w3schools linked here.

I am trying to figure out a way to make a similar gallery, except it goes through a loop of first flashing 5 images at .3s each, then sitting on one image for 5 seconds. Then repeating this process.

I have been trying to figure it out but I don't understand JavaScript enough to even figure out how to approach it. Any tips or direction would be extremely appreciated!

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

0

You might want to supply a timeout for each image, or specify which order of the image have a different timeout. Taking the w3school as an example you can do this

  1. Supply timeout for each image
function showSlides() {
  var i;
  var timeout = [2000, 5000, 3000] // timeout for image1, image2, image3
  var slides = document.getElementsByClassName("mySlides");
  var dots = document.getElementsByClassName("dot");
  for (i = 0; i < slides.length; i++) {
    slides[i].style.display = "none";  
  }
  slideIndex++;
  if (slideIndex > slides.length) {slideIndex = 1}    
  for (i = 0; i < dots.length; i++) {
    dots[i].className = dots[i].className.replace(" active", "");
  }
  slides[slideIndex-1].style.display = "block";  
  dots[slideIndex-1].className += " active";
  setTimeout(showSlides, timeout[slideIndex-1]); // get timeout based on current image order
}
  1. Add a condition based on order
function showSlides() {
  var i;
  var slides = document.getElementsByClassName("mySlides");
  var dots = document.getElementsByClassName("dot");
  for (i = 0; i < slides.length; i++) {
    slides[i].style.display = "none";  
  }
  slideIndex++;
  if (slideIndex > slides.length) {slideIndex = 1}    
  for (i = 0; i < dots.length; i++) {
    dots[i].className = dots[i].className.replace(" active", "");
  }
  slides[slideIndex-1].style.display = "block";  
  dots[slideIndex-1].className += " active";
  
  //make second image last for 5 seconds
  if(slideIndex === 2){
    setTimeout(showSlides, 5000); // Change image at 5 seconds
  }else{
    setTimeout(showSlides, 2000); // Change image at 2 seconds
  }
  
}

Do note that they are maybe a better way to do it, but I want to show you that you only need to supply the setTimeout with the proper timing that you want.

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