Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

189
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda