I am using the slick slider for my slides now I would like to get the previous slide index, I know how to get clicked slide index as follows
$('.carousel').on('afterChange', function() {
var dataId = $('.slick-current').attr("data-slick-index");
console.log(dataId);
});
so how do I get the previous slide index using Jquery?
I am using the slick slider for my slides now I would like to get the previous slide index, I know how to get clicked slide index as follows
$('.carousel').on('afterChange', function() {
var dataId = $('.slick-current').attr("data-slick-index");
console.log(dataId);
});
so how do I get the previous slide index using Jquery?
Share Improve this question asked Jul 7, 2021 at 10:36 The Dead ManThe Dead Man 5,57633 gold badges125 silver badges226 bronze badges2 Answers
Reset to default 5According to the Slick Event documentation the afterChange
event accepts a currentSlide
argument which is an integer value which is the index of the current slide. To get the index of the previous slide, subtract 1 from this value:
$('.carousel').on('afterChange', function(e, s, currentSlideIndex) {
let previousSlideIndex = currentSlideIndex - 1;
console.log(previousSlideIndex);
});
the answer provided is wrong. should just use cached variable from
.on('beforeChange', function (event, slick, currentSlide, nextSlide) {}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745281777a4620317.html
评论列表(0条)