未捕获的TypeError:$(...)。owlCarousel不是函数

时间:2017-08-04 23:22:47

标签: owl-carousel

我在尝试设置owl carousel时出现以下错误:

Uncaught TypeError: $(…).owlCarousel is not a function

这是我的头脑:

   <link href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.2.1/assets/owl.carousel.min.css" rel="stylesheet">
  <link href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.2.1/assets/owl.theme.default.min.css" rel="stylesheet">

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.2.1/owl.carousel.min.js"></script>
 {{ 'theme.js' | asset_url | script_tag }}

在我的theme.js中:

$(function() {

      $('.owl-carousel').owlCarousel({
        loop: true,
        margin: 20,
        responsiveClass: true,
        navText : ["<i class='fa fa-chevron-left'></i>","<i class='fa fa-chevron-right'></i>"],
        responsive: {
          0: {
            items: 1,
            nav: true
          },
          900: {
            items: 3,
            nav: true
          }
        },
      });
  });

以上设置有什么问题?

1 个答案:

答案 0 :(得分:0)

当文档和$(&#39; .owl-carousel&#39;)准备就绪时,您应该初始化owlCarousel。 演示:https://gyx8899.github.io/YX-JS-ToolKit/owlCarousel2/owl-navOnSide.html