Using slick, I have a simple carousel along the lines of:
<div class="carousel">
<div class="image"><img src="http://path/to/image.jpg" data-caption="Caption 1"></div>
<div class="image"><img src="http://path/to/image2.jpg" data-caption="Caption 2"></div>
<div class="image"><img src="http://path/to/image3.jpg" data-caption="Caption 3"></div>
</div>
I am initializing the carousel with an onAfterChange
function to try to update the caption in another div but am a bit confused about how to get this div as a dom or jquery object?
$('.carousel').slick({
lazyLoad: 'progressive',
onAfterChange: function(slider,index){
console.log(???);
}
});
Where slider
returns the carousel object and index
returns the current slide.
How could I get the data-caption
value out of this?
slick({ lazyLoad: 'progressive', onAfterChange: function(slider,index){ console. log(???); } }); Where slider returns the carousel object and index returns the current slide.
Slick is a fresh new jQuery plugin for creating fully customizable, responsive and mobile friendly carousels/sliders that work with any html elements.
try this
$('.carousel').on('afterChange', function() {
var dataId = $('.slick-current').attr("data-slick-index");
console.log(dataId);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With