My attempt to showcase an automated slideshow seems to be partially successful. The images are changing as intended, but the dots below aren't functioning properly. Although clicking on a dot triggers the desired action, I am aiming for all dots to turn white simultaneously with each slide transition.
Below is the HTML file snippet:
<div class="slideshow-container">
<div class="mySlides fade">
<img src="images/laptop.png" class="welcome__img" style="width:100%">
</div>
<div class="mySlides fade">
<img src="images/laptop.png" class="welcome__img" style="width:100%">
</div>
<div class="mySlides fade">
<img src="images/laptop.png" class="welcome__img" style="width:100%">
</div>
<div style="text-align:center">
<span class="dot" onclick="currentSlide(1)"></span>
<span class="dot" onclick="currentSlide(2)"></span>
<span class="dot" onclick="currentSlide(3)"></span>
</div>
</div>
Here is the CSS code:
.slideshow-container {
max-width: 1000px;
position: relative;
margin: auto;
}
/* Hide the images by default */
.mySlides {
display: none;
}
.dot {
cursor: pointer;
height: 10px;
width: 10px;
margin: 0 2px;
background-color: $grey;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
}
.active, .dot:hover {
background-color: $white;
}
/* Fading animation */
.fade {
-webkit-animation-name: fade;
-webkit-animation-duration: 1.5s;
animation-name: fade;
animation-duration: 1.5s;
}
@-webkit-keyframes fade {
from {opacity: .4}
to {opacity: 1}
}
@keyframes fade {
from {opacity: .4}
to {opacity: 1}
}
The JavaScript segment:
var slideIndex = 0;
showSlides();
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}
slides[slideIndex-1].style.display = "block";
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
setTimeout(showSlides, 2000); // Change image every 2 seconds
}
While the setTimeout function operates correctly, the issue persists with the dots failing to change their fill color.