如果你成功了
afterChange
调用前事件
.slick('resize')
function handleSlideChange(slick, currentSlide) {
// ...
}
function handleIsActiveClass() {
// Named function instead of anonymous function
$slickCarousel.on('afterChange', handleSlideChange);
}
function reInitSlickOnResize() {
$slickCarousel
.off('afterChange', handleSlideChange)
.slick('resize')
.on('afterChange', handleSlideChange);
}
$(window).on('resize orientationchange', reInitSlickOnResize);
另一种方法是使用标志来抑制行为:
var isResizing = false;
function handleIsActiveClass() {
$slickCarousel.on('afterChange', function (slick, currentSlide) {
if (isResizing) {
return;
}
// ...
});
}
function reInitSlickOnResize() {
isResizing = true;
$slickCarousel.slick('resize');
isResizing = false;
}