Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slick carousel responsive breakpoints

This is the configuration I am using to create a slick carousel on my web page:

$('#carousel').slick({
  infinite: true,
  slidesToShow: 3,
  slidesToScroll: 1,
  arrows: true,
  autoplay: true,
  autoplaySpeed: 2000,
  responsive: [
    {
      breakpoint: 1200,
      settings: {
        slidesToShow: 2,
        slidesToScroll: 1,
      },
    },
    {
      breakpoint: 1008,
      settings: {
        slidesToShow: 1,
        slidesToScroll: 1,
      },
    },
    {
      breakpoint: 800,
      settings: 'unslick',
    },
  ],
})

It is working the way it is supposed to work except for one thing... when I resize my browser window from width: 1920 to 800, the carousel unslicks it, and the content is displayed like normal divs.

But then when I increase the width of the browser window the carousel doesn't recreate it. It remains like HTML div blocks without carousel.

Any help would be appreciated.

like image 848
void Avatar asked Jul 28 '15 06:07

void


People also ask

Is slick slider responsive?

Fully responsive. Scales with its container. Uses CSS3 when available. Fully functional when not.

What is slider breakpoint?

Breakpoints are the pixel values where Smart Slider changes to show a different layout. For example, you can use breakpoints to make the slider switch to tablet view below 1199px screen width. Breakpoints in Smart Slider based on both the width and height of the browser where the slider displays.

How do you reinitialize slick slider?

After calling an request, set timeout to initialize slick slider. Do not initialize slick slider at start. Just initialize after an AJAX with timeout. That should work for you.


2 Answers

unslick is a destructor method. Once you unslick, you need to call slick() again to construct carousel.

like image 169
Peter Wong Avatar answered Sep 23 '22 12:09

Peter Wong


This is one way to rebuild the carousel after unslick kills it at a breakpoint:

$(window).resize(function () {
    $('.js-slider').not('.slick-initialized').slick('resize');
});

$(window).on('orientationchange', function () {
    $('.js-slider').not('.slick-initialized').slick('resize');
});
like image 32
Beck Johnson Avatar answered Sep 21 '22 12:09

Beck Johnson