I have a carousel slide from the bootstrap, I wanted to know when a certain slide is going on the screen using javascript or stop at the last slide.
I have a carousel slide from the bootstrap, I wanted to know when a certain slide is going on the screen using javascript or stop at the last slide.
I have already found the solution, below the link to the example in w3schools link
It looks like this: I put an id on each item and used the 'slid.bs.carousel' that occurs when the carousel runs from one item to another.
<header id="myCarousel" class="carousel slide">
<div class="carousel-inner">
<div class="item active" id="1">
<div class="fill" style="background-image:url('../img/foto1.png');"></div>
</div>
<div class="item" id="2">
<div class="fill" style="background-image:url('../img/foto2.png');"></div>
</div>
<div class="item" id="3">
<div class="fill" style="background-image:url('../img/foto3.png');"></div>
<script>
$('.carousel').carousel({
interval: 5000 //changes the speed
})
$("#myCarousel").on('slid.bs.carousel', function () {
var i = $(".active").attr("id");
alert(i);
console.log(i);
});
</script>