Reinitialize Slick js after successful ajax call

前端 未结 11 1614
傲寒
傲寒 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:27

    I was facing an issue where Slick carousel wasn't refreshing on new data, it was appending new slides to previous ones, I found an answer which solved my problem, it's very simple.

    try unslick, then assign your new data which is being rendered inside slick carousel, and then initialize slick again. these were the steps for me:

    jQuery('.class-or-#id').slick('unslick');
    myData = my-new-data;
    jQuery('.class-or-#id').slick({slick options});
    

    Note: check slick website for syntax just in case. also make sure you are not using unslick before slick is even initialized, what that means is simply initialize (like this jquery('.my-class').slick({options}); the first ajax call and once it is initialized then follow above steps, you may wanna use if else

提交回复
热议问题