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!
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
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
}
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.