I have the following HTML structure:
<div class="slider">
<div class="slide fade ativa"> <img src="_img/_banner/_site/bg_1.jpg" /> <span>Este é 1</span> </div>
<div class="slide fade"> <img src="_img/_banner/_site/bg_2.jpg" /> <span>Este é 2</span> </div>
<div class="slide fade"> <img src="_img/_banner/_site/bg_3.jpg" /> <span>Este é 3</span> </div>
<nav>
<button class="anterior">Anterior</button>
<button class="proximo">Próximo</button>
</nav>
</div>
I need to run inside the div.slider, all, and only, divs.slide excluding the buttons in the loop. How do I?
The goal is to create a slide in which, when you get to the last div, retune the loop to the first div. The way I'm doing below is not working.
const blocos = $("div.slider div.slide");
function startslider() {
ativa = $("div.slider div.ativa")
if (!$(ativa).next().length) {
ativa = blocos.first()
}
$(ativa)
.removeClass("ativa")
.next()
.addClass("ativa")
setTimeout(startslider, 5000)
}
setTimeout(startslider, 5000)