jquery - 如何使用一个导航滑动 2 个 Owl 旋转木马
问题描述
我正在使用Owl-Carousel 2.3.4 版本,我需要使用一个滑块上的导航同时滑动 2 个轮播的内容,我需要所有类型(上一个/下一个按钮、点、触摸滑动)。
对于 Owl-carousel v1.3.3,我在这里找到了一个可行的解决方案:http:
//jsfiddle.net/m3n2q60d/40/
$(document).ready(function(){
var o2 = $('#c1')
o2.owlCarousel({
items:1,
singleItem:true,
loop:true,
margin:10,
navigation :true,
touchDrag: true,
mouseDrag: true,
afterMove: function (elem) {
var current = this.currentItem;
o1.trigger('owl.goTo',current);
}
});
var o1 = $('#c2');
o1.owlCarousel({
items:1,
singleItem:true,
loop:true,
margin:10,
pagination:false,
navigation :false,
touchDrag: true,
mouseDrag: false,
afterMove: function (elem) {
var current = this.currentItem;
o2.trigger('owl.goTo',current);
}
});
});
但它不适用于 v2.3.4,因为“afterMove”选项在新版本中不可用。
http://jsfiddle.net/m3n2q60d/18/
有人可以为 Owl-carousel 2 提出解决方案吗?
解决方案
我认为您需要编写单独的 onclick 函数,如下所示。
$(document).ready(function() {
var o1 = $('#c1'), o2 = $('#c2');
//Sync o2 by o1
o1.on('click', '.owl-next', function () {
o2.trigger('next.owl.carousel')
});
o1.on('click', '.owl-prev', function () {
o2.trigger('prev.owl.carousel')
});
//Sync o1 by o2
o2.on('click', '.owl-next', function () {
o1.trigger('next.owl.carousel')
});
o2.on('click', '.owl-prev', function () {
o1.trigger('prev.owl.carousel')
});
//Carousel settings
o1.owlCarousel({
center : true,
loop : true,
items : 1,
margin:0,
nav : true
});
o2.owlCarousel({
center : true,
loop : true,
items : 1,
margin:0,
nav : true
});
});
请检查我创建的小提琴。
推荐阅读
- c# - 如何防止继承控件的组件出现在 Visual Studio 属性窗格中进行编辑?
- arrays - 一个包含 bash 中的子字符串的字符串 - 不工作
- swift - 如何在 Swift 中只隐藏键盘而不是 inputAccessoryView
- node.js - 如何使用 elemMatch
- c - 在 c 中搜索 char* 以查找 char* 数组的成员
- python - 如何读取带有 .zip 扩展名的 URL 并获取文件 .txt 并将其保存在目录中?
- python - ValueError:具有多个元素的数组的真值不明确。在 If 条件中使用相等时出错
- python - 是否可以从一个列表中复制一个项目并多次放入另一个列表中,然后单独修改每个项目?
- javascript - 如何在node.js中自动将图像从目录上传到axios
- android - RecyclerView 中项目之间的空间