Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!