Slick slider options change

user3803100 picture user3803100 · Aug 17, 2015 · Viewed 18.5k times · Source

I'd like to know if there is any way to pass new options to already created Slick carousel? I have this code:

$('.bottom-slider').slick({
  asNavFor: '.top-slider',
  slidesToShow: 3,
  slidesToScroll: 1,
  variableWidth: true,
  centerMode: true,
  etc...
});

and at some moment (added CSS class to restyle slider) I'd like to pass slidesToShow: 5 to carousel. I tried with

$('.bottom-slider').slick({slidesToShow: 5}); 

but it doesn't work. Is it possible? I prefer not to destroy/run again slider or create second box with "restyled" carousel.

Answer

vincenttsao14 picture vincenttsao14 · Sep 6, 2018

I found the description of slickSetOption on the website to be a bit confusing, so leaving a couple examples here.

Set single option without UI refresh:

$('.initialized-carousel').slick('slickSetOption', 'slidesToShow', 3);

Set multiple options with UI refresh:

$('.initialized-carousel').slick('slickSetOption', {
   slidesToShow: 3,
   slidesToScroll: 1
}, true);