Reinitialize Slick js after successful ajax call

前端 未结 11 1803
傲寒
傲寒 2021-02-01 16:52

I am using Slick for a carousel implementation and everything works fine when the pages loads.What I am trying to achieve is that when i make an Ajax call to retrieve new data I

11条回答
  •  没有蜡笔的小新
    2021-02-01 17:29

    The best way would be to use the unslick setting or function(depending on your version of slick) as stated in the other answers but that did not work for me. I'm getting some errors from slick that seem to be related to this.

    What did work for now, however, is removing the slick-initialized and slick-slider classes from the container before reinitializing slick, like so:

    function slickCarousel() {
        $('.skills_section').removeClass("slick-initialized slick-slider");
        $('.skills_section').slick({
            infinite: true,
            slidesToShow: 3,
            slidesToScroll: 1
        });
    }
    

    Removing the classes doesn't seem to initiate the destroy event(not tested but makes sense) but does cause the later slick() call to behave properly so as long as you don't have any triggers on destroy, you should be good.

提交回复
热议问题