I'm working on a bootstrap carousel in which it shows the image first and then the caption slides in from the right after a few seconds. It works but there's an issue with the first slide, where it shows the caption of the first slide when it moves to the second it only is being hidden after a second and then the new caption slides in.
This is my code:
<div class="carousel-inner">
<div class="item active">
<img src="test.png" alt="Chicago">
<div class="carousel-caption">
<div class="carousel-caption-inner" data-interval="2000">
<p class="slider-text small"><span class="slider-padding">what makes</span> us <span class="slider-green" id="banner-change">specialists?</span></p>
<p class="slider-text">We just do ip</p>
<p class="slider-text"><span class="slider-green">exceptionally</span></p>
</div>
</div>
</div>
<div class="item">
<img src="test.png" alt="Chicago">
<div class="carousel-caption">
<div class="carousel-caption-inner">
<p class="slider-text small"><span class="slider-padding">what makes</span> us <span class="slider-green">distinctive?</span></p>
<p class="slider-text">Market leading</p>
<p class="slider-text"><span class="slider-green"> brought to life</span> and outside london</p>
</div>
</div>
</div>
<div class="item">
<img src="test.png" alt="Chicago">
<div class="carousel-caption">
<div class="carousel-caption-inner">
<p class="slider-text small"><span class="slider-padding">what makes</span> us <span class="slider-green">stand out?</span></p>
<p class="slider-text">The <span class="slider-green">only way</span> to do great work is to love what you do</p>
</div>
</div>
</div>
<div class="item">
<img src="test.png" alt="Los Angeles">
<div class="carousel-caption">
<div class="carousel-caption-inner">
<p class="slider-text small"><span class="slider-padding">what makes</span> us <span class="slider-green">the right choice?</span></p>
<p class="slider-text">holistic thinking,<span class="slider-green"> made real</span></p>
</div>
</div>
</div>
<div class="item">
<img src="test.png" alt="New York">
<div class="carousel-caption">
<div class="carousel-caption-inner">
<p class="slider-text small"><span class="slider-padding">what makes</span> us <span class="slider-green">effective?</span></p>
<p class="slider-text">Intellectual property</p>
<p class="slider-text">- <span class="slider-green"> brought to life</span></p>
</div>
</div>
</div>
</div>
</div>
And:
<script type="text/javascript">
var carouselContainer = $('.carousel');
var slideInterval = 3000;
$( document ).ready(function() {
function toggleCaption() {
$('.carousel-caption').hide();
var caption =
carouselContainer.find('.active').find('.carousel-
caption');
caption.delay(1000).toggle("slide", {direction:'right'});
}
carouselContainer.carousel({
interval: slideInterval,
cycle: true,
pause: "hover"
}).on('slid.bs.carousel', function() {
toggleCaption();
});
});
</script>
Anybody know how I could fix this? It seems the function is only activated on the second slide, not the first.