I have a vertical slick.js carousel and I have some custom javaScript to handle mousewheel scrolling, I would like to disable this when the user gets to the last slide.
Some example code.
$(".slick").slick({
adaptiveHeight: true,
vertical: true,
verticalSwiping: true,
autoPlay: false,
infinite: false,
useCSS: false,
slidesToShow: 1,
slidesToScroll: 1,
dots: false,
arrows: false,
});
let blocked = false;
let blockTimeout = null;
let prevDeltaY = 0;
// Handling mouse wheel action.
$(".slick").on("mousewheel DOMMouseScroll wheel", function (e) {
let deltaY = e.originalEvent.deltaY;
e.preventDefault();
e.stopPropagation();
clearTimeout(blockTimeout);
blockTimeout = setTimeout(function () {
blocked = false;
}, 100);
if (
(deltaY > 0 && deltaY > prevDeltaY) ||
(deltaY < 0 && deltaY < prevDeltaY) ||
!blocked
) {
blocked = true;
prevDeltaY = deltaY;
if (deltaY > 0) {
$(this).slick("slickNext");
} else {
$(this).slick("slickPrev");
}
}
});
$(".slick").on("afterChange", function (event, slick, currentSlide) {
console.log(slick, currentSlide);
if (slick.$slides.length - 1 == currentSlide) {
console.log("I am at the Last slide");
}
});
I think this is something I should do in the afterChange function, any recommendations?