I have a bootstrap 4.0 carousel and I want zooming effect when each slides active. I have used transform: scale
property for achieving it. I have applied transform: scale
to .carousel-item.active img
element. And I have added active class for first element using jquery. The animation is not working for my first slide. When it loops it works. I have tried to add the class in setTimeOut function, but it didn't help. Can any one please help me?
These are my codes
html
<div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item">
<img class="d-block w-100" src="https://placeimg.com/640/480/any" alt="First slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="https://placeimg.com/640/480/nature" alt="Second slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="https://placeimg.com/640/480/animals" alt="Third slide">
</div>
</div>
<a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
css
.carousel-item img{
transition: all 1s;
transform:scale(1);
}
.carousel-item.active img{
transform:scale(1.2);
}
jquery
window.setTimeout(function(){
$('#carouselExampleControls .carousel-item:first-child').addClass('active');
},2000);