[英]How to get previous slide index in slick slide
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我正在为我的幻灯片使用光滑的 slider 现在我想获得以前的幻灯片索引,我知道如何获得点击的幻灯片索引如下
$('.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?那么如何使用 Jquery 获取上一张幻灯片索引?
According 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.根据Slick Event 文档,
afterChange
事件接受一个currentSlide
参数,它是一个整数值,它是当前幻灯片的索引。 To get the index of the previous slide, subtract 1 from this value:要获取上一张幻灯片的索引,请从此值中减去 1:
$('.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) {}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.