javascript - 在主js文件中调用owl carousel时出错
问题描述
我对编码尤其是 JavaScript 真的很陌生。我似乎无法让 Owl Carousel 工作:(
当我将 main.js 文件保存在括号中时,出现一些错误:
$(document).ready(function(){
$(".owl-carousel").owlCarousel();
});
错误:
$' was used before it was defined. $(document).ready(function(){
1
Expected exactly one space between 'function' and '('. $(document).ready(function(){
1
Expected exactly one space between ')' and '{'. $(document).ready(function(){
1
Missing space between ')' and '{'. $(document).ready(function(){
2
Missing 'use strict' statement. $(".owl-carousel").owlCarousel();
我快要发疯了,因为我已经正确地包含了所有内容,并且我不知道错误的含义是什么...
这是我的 index.html
<div class="owl-carousel">
<div> Your Content </div>
<div> Your Content </div>
<div> Your Content </div>
<div> Your Content </div>
<div> Your Content </div>
<div> Your Content </div>
<div> Your Content </div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="js/owl.carousel.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/main.js"></script>
请帮忙,谢谢:)
解决方案
首先请删除 2.2.4 和 1.12.4 的 jquery 库。其次是 main.js。遵循此代码。
$(".owl-carousel").owlCarousel({
responsiveClass: true,
dots: true,
dotsContainer: false,
loop: true,
autoWidth: true,
autoplay:true,
nav:true,
smartSpeed:1000,
items:4,
responsive: {
0: {
items:1,
margin: 250,
center: true
},
768: {
items:3,
margin:200,
center: false
},
992: {
items:3,
margin: 350,
center: true
},
1200: {
items:3,
margin:350,
center: true
},
},
});
添加以下CSS
.owl-nav {
text-align: center;
}
然后在样式表中添加owl.carousel.min.css
https://cdn.boomcdn.com/libs/owl-carousel/2.3.4/assets/owl.carousel.min.css "
您可以添加自定义 CSS 并相应地添加更改。请在此处参考 Owl Carousel 文档
推荐阅读
- javascript - 将从函数返回的数据传递给聚合物自定义元素
- paypal - 沙盒贝宝集成
- java - 如何在 JAVA 中知道我的 CSV 文件列的数据类型
- c# - Datagridview 值被存储为 Null
- python-3.x - 分页 Webscraping Python3- BS4 - While 循环
- tensorflow - 用于对象检测的训练图像数据集
- arrays - SWIFT 单元格填充
- python - 如何调用另一个函数(温度)作为主函数
- swift - AVAudioPlayer 没有快速播放。如何解决?
- reactjs - 在 React 的 render() 方法中显示选定的选项