Reinitialize Slick js after successful ajax call

前端 未结 11 1616
傲寒
傲寒 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条回答
  •  梦毁少年i
    2021-02-01 17:27

    After calling an request, set timeout to initialize slick slider.

    var options = {
        arrows: false,
        slidesToShow: 1,
        variableWidth: true,
        centerPadding: '10px'
    }
    
    $.ajax({
        type: "GET",
        url: review_url+"?page="+page,
        success: function(result){
            setTimeout(function () {
                $(".reviews-page-carousel").slick(options)
            }, 500);
        }
    })
    

    Do not initialize slick slider at start. Just initialize after an AJAX with timeout. That should work for you.

提交回复
热议问题