Slick carousel has 0px width when loaded in collapsed tab

允我心安 提交于 2020-04-06 06:47:08

问题


When loading slick slider in collapsed content (angular-bootstrap collapse plugin in this case) the .slick-track div gets 0px width, resulting in the slider trying to fit all slides on top of eachother. When pressing arrow to see next slide, the slides go back to normal. If I select the slider and want to check the components in my browser, it also goes back to normal.

Please see this example: http://plnkr.co/edit/iw9f2alEnK0HFkv1eq16?p=preview

This is the slick configuration I'm using:

$(document).ready(function(){
    $('.tourImageSlider').slick({
          dots: true,
          infinite: false,
          slidesToShow: 3,
          slidesToScroll: 1,
          responsive: [
            {
              breakpoint: 1500,
              settings: {
                slidesToShow: 2,
                slidesToScroll: 1,
              }
            },
            {
              breakpoint: 1000,
              settings: {
                slidesToShow: 1,
                slidesToScroll: 1,
              }
            }]
    });
});

Would anyone have an idea of how to solve this?


回答1:


Finally I got the answer by slick creator Ken Wheeler himself. When collapsable content is triggered open, simply call the following line:

$('.slider-class').slick('setPosition');

...and replace "slider-class" with the class name of your slider. Personally I created an angular function with this line, and triggered it with ng-open.



来源:https://stackoverflow.com/questions/31955382/slick-carousel-has-0px-width-when-loaded-in-collapsed-tab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!