Slick Carousel Uncaught TypeError: $(…).slick is not a function

前端 未结 15 1596
独厮守ぢ
独厮守ぢ 2020-12-10 00:18

Somehow I\'m unable to use slick carousel (http://kenwheeler.github.io/slick/) correctly.

I\'m getting the following error:

Uncaught TypeError: $(..         


        
15条回答
  •  一向
    一向 (楼主)
    2020-12-10 01:06

    Old question, but I have only one recent jQuery file (v3.2.1) included (slick is also included, of course), and I still got this problem. I fixed it like this:

    function initSlider(selector, options) {
        if ($.fn.slick) {
            $(selector).slick(options);
        } else {
            setTimeout(function() {
                initSlider(selector, options);
            }, 500);
        }
    }
    
    //example: initSlider('.references', {...slick's options...});
    

    This function tries to apply slick 2 times a second and stops after get it working. I didn't analyze it deep, but I think slick's initialization is being deferred.

提交回复
热议问题