admin管理员组文章数量:1418083
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) {}
本文标签: javascriptHow to get previous slide index in slick slideStack Overflow
版权声明:本文标题:javascript - How to get previous slide index in slick slide - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745281776a2651462.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论