Slick: Pass the direction of change in the beforeChange and afterChange events

Created on 29 Aug 2015  路  11Comments  路  Source: kenwheeler/slick

When Slick calls beforeChange, it passes prevSlide and nextSlide. This cannot be used to determine the direction of the slide in case of infinity loop.

Feature Request

Most helpful comment

@brsanthu I'm sure this could be cleaner but it gets the job done for now (at least in beforeChange):

if ((currentSlide > nextSlide && (nextSlide !== 0 || currentSlide === 1)) || (currentSlide === 0 && nextSlide === slick.slideCount - 1)) {
    console.log('previous');
}
else {
    console.log('next');
}

All 11 comments

+1

@brsanthu I'm sure this could be cleaner but it gets the job done for now (at least in beforeChange):

if ((currentSlide > nextSlide && (nextSlide !== 0 || currentSlide === 1)) || (currentSlide === 0 && nextSlide === slick.slideCount - 1)) {
    console.log('previous');
}
else {
    console.log('next');
}

@drastick thank you

+1

@drastick unfortunately this will not work for only 2 slides, otherwise perfect

@drastick Works for an infinite loop's autoplay or previous/next buttons. But it doesn't work for the dots.

+1

+1

+1

@drastick Your solution works! Tks!

Thank you....

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yangkennyk picture yangkennyk  路  3Comments

stephane-r picture stephane-r  路  3Comments

hoghamburg picture hoghamburg  路  3Comments

REPTILEHAUS picture REPTILEHAUS  路  3Comments

ericestes picture ericestes  路  3Comments