kenwheeler / slick

the last carousel you'll ever need
kenwheeler.github.io/slick
MIT License
28.49k stars 5.89k forks source link

autoPlayIterator function does not change direction when infinite is false and slidesToScroll is bigger than one #3376

Open slartibart70 opened 6 years ago

slartibart70 commented 6 years ago

Hi, we have slick with autoplay set to true and infinite is false. Number of slides to scroll is 2 Slick (auto)scrolls successfully to the right and returns to the left but misses to detect the direction change needed to scroll again to the right.

So, fix would be in Slick.prototype.autoPlayIterator = function() {} line 424, by replacing if ( _.currentSlide - 1 === 0 ) {}

with either if ( .currentSlide - .options.slidesToScroll === 0 ) {} or with if ( _.currentSlide - 1 <= 0 ) {

which changes direction to 1 again.

slartibart70 commented 6 years ago

i would propose another bugfix: If the autoscroll reaches the right end, it waits double time before it scrolls back. Better to have the function replaced by this (taking the above change into account)

Slick.prototype.autoPlayIterator = function() {

    var _ = this,
        slideTo = _.currentSlide + _.options.slidesToScroll;

    if ( !_.paused && !_.interrupted && !_.focussed ) {

        if ( _.options.infinite === false ) {

            if ( _.direction === 1 && ( _.currentSlide + 1 ) === ( _.slideCount - 1 )) {
                _.direction = 0;
            }

            if ( _.direction === 0 ) {

                slideTo = _.currentSlide - _.options.slidesToScroll;

                if ( _.currentSlide - _.options.slidesToScroll === 0 ) {
                    _.direction = 1;
                }

            }

        }

        _.slideHandler( slideTo );

    }

};