Currently, I am in the process of developing a JavaScript script that will cycle through a series of images within the same <div>
. The goal is to create a seamless animation effect with the image transitions. Although the images are cycling through, the transition is not as smooth as desired.
var slideIndex = 0;
showSlides();
function showSlides() {
var i;
var slides = document.getElementsByClassName("mySlides");
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
slides[i].style.opacity = "0";
}
slideIndex++;
if (slideIndex > slides.length) {
slideIndex = 1
}
slides[slideIndex - 1].style.display = "block";
slides[slideIndex - 1].style.opacity = "1";
setTimeout(showSlides, 2500);
// Implementing a transition effect on the images.
slides[slideIndex - 1].style.transition = "all 2.50s";
// Introducing a delay for the images during transition.
slides[slideIndex - 1].style.transitionDelay = "2.50s";
}
<div class="p-centered">
<img src="https://picsum.photos/200?1" class="img-responsive mySlides" alt="">
<img src="https://picsum.photos/200?2" class="img-responsive mySlides" alt="">
<img src="https://picsum.photos/200?3" class="img-responsive mySlides" alt="">
<img src="https://picsum.photos/200?4" class="img-responsive mySlides" alt="">
<img src="https://picsum.photos/200?5" class="img-responsive mySlides" alt="">
</div>