I have a carousel sliders with text that I've customized using my own JavaScript. The carousel arrows work properly, but I want the sliders to automatically move after a set interval.
Here's the HTML
<div class="col-6 col-xs-12 " style="text-align:-webkit-center;">
<div class="slideshow-container">
<div class="mySlides w3-container w3-center w3-animate-right">
<h2 class="font-size" id="f37" data-animation="fadeInUp" data-delay="200ms">1</h2>
</div>
<div class="mySlides w3-container w3-center w3-animate-right">
<h2 class="font-size" id="f37" data-animation="fadeInUp" data-delay="200ms">2</h2>
</div>
<div class="mySlides w3-container w3-center w3-animate-right">
<h2 class="font-size" id="f37" data-animation="fadeInUp" data-delay="200ms">3</h2>
</div>
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>
</div>
Here's the JS
<script>
var slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex += n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("dot");
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
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";
}
</script>
I hope my question is clear. Any help would be greatly appreciated. I've added the code to codepen so you can see the strange behavior it exhibits when the arrows are clicked, despite the auto-slides working correctly when idle. https://codepen.io/mahirq8/pen/JjjJzbe
Thank you