2
I’m having a problem at the carousel using jQuery:
I can’t get him to stop transitioning the images by clicking a button.
Follows the code:
$('#slide img:eq(0)').addClass("ativo").show();
var text = $('.ativo').attr("alt");
$("#slide").prepend("<p>" + text + "</p>");
var t = setInterval(slide, 5000);
$('#stop').hover(function(event) {
clearInterval(t);
}, function() {
setInterval(slide, 5000);
});
function slide() {
if ($('.ativo').next().size()) {
$('.ativo').fadeOut(2000).removeClass('ativo').next().fadeIn(2000).addClass('ativo');
} else {
$('.ativo').fadeOut(2000).removeClass('ativo');
$('#slide img:eq(0)').fadeIn(2000).addClass('ativo');
}
var text = $('.ativo').attr('alt');
$('#slide p').hide().html(text).delay(500).fadeIn(2000);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<figure id="slide">
<img src="img/paisagem.jpg" alt="imagem 1">
<img src="img/logo.jpg" alt="Imagem 2">
<img src="img/paisagem.jpg" alt="Imagem 3">
</figure>
<button id='start'>Start</button>
<button id='stop'>Stop</button>
It worked, thank you very much for the tip :)
– Bruno Cabral
@Brunocabral If my reply helped you, please mark it as accepted by clicking on the checkmark on the left side of the text! :)
– Daniel