How can I know what direction the carousel are going on the event onBeforeChange
. right or left?
$('.foo').slick
infinite: false
onBeforeChange: (e) ->
if right
do_this()
if left
do_that()
beforeChange event get you an access to currentSlide and nextSlide values.
It works for infinite sliders too.
So, the code is:
$(".some-element").on('beforeChange', function (event, slick, currentSlide, nextSlide) {
if (Math.abs(nextSlide - currentSlide) == 1) {
direction = (nextSlide - currentSlide > 0) ? "right" : "left";
}
else {
direction = (nextSlide - currentSlide > 0) ? "left" : "right";
}
});