kenwheeler / slick

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

SlickGoTo Event conflict with SlidesToShow and Doesn't change the slide to specified index #4264

Closed Arifursdev closed 1 year ago

Arifursdev commented 1 year ago

SlickGoTo Event conflicts with SlidesToShow. and doesn't change the slide to specified index. basically without infinite and centerMode it has the issue. its possibly happening because its not able to find enough items on its side so it can change the current-slide in the first column of the row.

example: http://jsfiddle.net/w3ogkxph/

====================================================================

Steps to reproduce the problem

<div class="test-carousel">

  <div class="item">
    Item text 1
  </div>
  <div class="item">
    Item text 2
  </div>
  <div class="item">
    Item text 3
  </div>
  <div class="item">
    Item text 4
  </div>
  <div class="item">
    Item text 5
  </div>
  <div class="item">
    Item text 6
  </div>
  <div class="item">
    Item text 7
  </div>
  <div class="item">
    Item text 8
  </div>

</div>

init carousel showing 4 item per row and in slideCount is 8 as seen above

$('.test-carousel').slick({
    arrows: false,
    dots: false,
    infinite: false,
    speed: 400,
    slidesToShow: 4,
    swipeToSlide: true,
    adaptiveHeight: true,
    responsive: [
      {
        breakpoint: 991,
        settings: {
          slidesToShow: 3
        }
      },
      {
        breakpoint: 768,
        settings: {
          slidesToShow: 2,
        }
      },
      {
        breakpoint: 420,
        settings: {
          slidesToShow: 1,
          centerMode: true,
          centerPadding: '40px'
        }
      }
    ]
  })

when running this, it won't change. possibly because they can't find another items after the last item and can't display the last item in first column in the row as slick does.

$('.test-carousel').slick('slickGoTo', 7)

solution could be something like this works but not yet implemented fully for responsive breakpoints slidesToShow

let totalItems = 8;
let slidesToShow = 4;

if (index >= totalItems - slidesToShow) {
      index = index - (totalItems - slidesToShow) + 1;
      $('.test-carousel').slick('slickGoTo', index)
      return;
 }

More Details

jQuery Latest v3.7.0 Slick 1.8.1, I believe the bug exists on 1.9.0 as well as seen on cdnjs

Arifursdev commented 1 year ago

should be fixed in PR #4265

pablo67340 commented 1 year ago

I have gone ahead and merged #4265 into pr-clean.