I'm implementing a Flickity slideshow, which includes a Slide counter at the bottom, and slide caption at the top. I've got them both in however the Caption at the top won't display what should be the img alt tag.
This is what I have - JSfiddle
HTML :
<section class="ux-carousel">
<div class="carousel">
<div class="carousel-cell">
<img class="carousel-cell-image" src="https://source.unsplash.com/5i8l46zW8do" alt="Image 01" width="1170" height="685" />
</div>
<div class="carousel-cell">
<img class="carousel-cell-image" src="https://source.unsplash.com/5i8l46zW8do" alt="Image 01" width="1170" height="685" />
</div>
</div>
<div class="carousel-counter">
<p class="carousel-status"></p>
</div>
<div class="carousel-caption">
<p class="caption"> </p>
</div>
</section>
Jquery :
var flkty = new Flickity('.carousel', {
imagesLoaded: true,
percentPosition: false,
pageDots: false
});
var carouselStatus = document.querySelector('.carousel-status');
var caption = document.querySelector('.caption');
function updateStatus() {
var slideNumber = flkty.selectedIndex + 1;
carouselStatus.textContent = slideNumber + '/' + flkty.slides.length;
}
flkty.on( 'select', function() {
// set image caption using img's alt
caption.textContent = flkty.selectedElement.alt;
});
updateStatus();
flkty.on( 'select', updateStatus );