Slick carousel - force slides to have the same height

前端 未结 8 1993
刺人心
刺人心 2021-02-01 01:21

Im having trouble with the Slick carousel JS plugin with multiple slidesToShow which have different heights.

I need the Slides to have the same

8条回答
  •  野性不改
    2021-02-01 02:00

    Ok guys i found an easy solution. Just add a setPosition callback function (fires after position/size changes) which sets the height of the slides to the height of the slider (slideTrack):

    JS

    $('.slider').slick({
        autoplay: false,
        dots: false,
        infinite: false,
        arrows: false,
        slidesToShow: 2,
        slidesToScroll: 2,
      rows: 0
    })
    .on('setPosition', function (event, slick) {
        slick.$slides.css('height', slick.$slideTrack.height() + 'px');
    });
    

    Dont forget that your slides need to have full height:

    CSS

    .slide {
      height: 100%;
    }
    

    Here is a little jsFiddle to demonstrate: https://jsfiddle.net/JJaun/o29a4q45/

提交回复
热议问题