Slick carousel shows two rows instead of one

后端 未结 1 1010
傲寒
傲寒 2021-01-16 03:44

I am building a website and I am using the Slick carousel for some sliders. I run into an issue where I have it set up with 3 slides and the option to show two rows if there

1条回答
  •  梦毁少年i
    2021-01-16 04:30

    You can accomplish this by getting the total number of slides and then conditionally defining the value of the rows setting. You should also set the value for slidesPerRow.

    const numSlides = $('.piece').length;
    
    const slickOptions = {
            
            rows: (numSlides > 3 ? 2 : 1),
            slidesPerRow: 3,
            slidesToShow: (numSlides > 3 ? 1 : 3),
            slidesToScroll: 1,
    
            dots: true,
            arrows: false,
            dotsClass: 'slick-dots slick-dots-black',
            adaptiveHeight: true
    };
    
    $('#slides').slick(slickOptions);
    

    0 讨论(0)
提交回复
热议问题