javascript - 未捕获的类型错误 - 无法读取 null 的属性 'owlcarousel'

标签 javascript jquery css magento

之前有人问过这个问题,但在按照给出的建议进行操作后,我仍然遇到同样的问题。 Uncaught typeError: Cannot read property 'owlCarousel' of null

我有一个 Magento 商店,使用名为 Ultimo 的模板。我想复制主页上的品牌 slider 以显示凭据。 slider 使用 Lazy Owl,我只将 CSS、jQuery 和 html 粘贴到我的 CMS 主页,无论我做什么,即使用 jQuery 而不是 $ 或添加 noConflict,问题仍然存在。

网站是www.lifestylemedicine.co.uk

代码是:

<style>
#owl-demo .item{
background: #3fbf79;
padding: 30px 0px;
margin: 10px;
color: #FFF;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
text-align: center;
}
.customNavigation{
text-align: center;
}

.customNavigation a{
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
</style>
<script>
$(document).ready(function() {

var owl = $("#owl-demo");

owl.owlCarousel({
  items : 10, //10 items above 1000px browser width
  itemsDesktop : [1000,5], //5 items between 1000px and 901px
  itemsDesktopSmall : [900,3], // betweem 900px and 601px
  itemsTablet: [600,2], //2 items between 600 and 0
  itemsMobile : false // itemsMobile disabled - inherit from itemsTablet option
});

// Custom Navigation Events
$(".next").click(function(){
owl.trigger('owl.next');
})
$(".prev").click(function(){
owl.trigger('owl.prev');
})
$(".play").click(function(){
owl.trigger('owl.play',1000); //owl.play event accept autoPlay speed as     second parameter
})
$(".stop").click(function(){
owl.trigger('owl.stop');
})

});
</script>
<h3 class="section-title padding-right">OUR CREDENTIALS</h3>
<div id="owl-demo" class="owl-carousel owl-theme">
<div class="item"><h1>1</h1></div>
<div class="item"><h1>2</h1></div>
<div class="item"><h1>3</h1></div>
<div class="item"><h1>4</h1></div>
<div class="item"><h1>5</h1></div>
<div class="item"><h1>6</h1></div>
<div class="item"><h1>7</h1></div>
<div class="item"><h1>8</h1></div>
<div class="item"><h1>9</h1></div>
<div class="item"><h1>10</h1></div>
</div>

<div class="customNavigation">
<a class="btn prev">Previous</a>
<a class="btn next">Next</a>
</div>

我将不胜感激。

最佳答案

执行此操作之前请检查是否加载了 js 文件:

owl.owlCarousel({
  items : 10, //10 items above 1000px browser width
  itemsDesktop : [1000,5], //5 items between 1000px and 901px
  itemsDesktopSmall : [900,3], // betweem 900px and 601px
  itemsTablet: [600,2], //2 items between 600 and 0
  itemsMobile : false // itemsMobile disabled - inherit from itemsTablet option
});

库的包含应如下所示:

<!-- Include js plugin -->
<script src="assets/owl-carousel/owl.carousel.js"></script>

别忘了您还需要 Jquery 库。

关于javascript - 未捕获的类型错误 - 无法读取 null 的属性 'owlcarousel',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32333697/

相关文章:

javascript - Angular 2 动态引导应用程序组件

javascript - 如何验证 SVG img 在 Firefox 中正确加载(在 webdriver 测试中)

javascript - 使用 AJAX 单击按钮打开 PDF 文件

html - 居中导航栏不起作用

javascript - 向场景添加光没有效果

javascript - JQuery/Ajax 和 when/done/promise 混淆

javascript - 将选项添加到我的 Select2

css - 数据表限制行高

html - 中心球员元素

javascript - 如何在不链接到播放列表的情况下播放两个 Youtube 视频?