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

给你一囗甜甜゛ 提交于 2019-12-12 04:11:57

问题


I'm getting the below error trying to setup owl carousel:

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

Here's from my head:

   <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 }}

And in my 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
          }
        },
      });
  });

What's wrong with above setup?


回答1:


You should init owlCarousel when the document and $('.owl-carousel') is ready. Demo: https://gyx8899.github.io/YX-JS-ToolKit/pages/owlCarousel2/owl-navOnSide.html



来源:https://stackoverflow.com/questions/45516738/uncaught-typeerror-owlcarousel-is-not-a-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!