【发布时间】:2019-04-02 07:36:37
【问题描述】:
我这里有两个带有自定义导航的猫头鹰旋转木马,当只有一个旋转木马时工作,但当我添加多个旋转木马时,所有旋转木马的功能相同,而不是独立
这是我的FIDDLE
这是我的 JS 代码
jQuery(function(){
var owl = jQuery('.owl-carousel');
owl.owlCarousel({
autoplay: 2000,
items:1,
nav:false,
autoplay:true,
autoplayTimeout:5000,
autoplayHoverPause:true,
loop: true,
dots: false,
onInitialized : counter, //When the plugin has initialized.
onTranslated : counter //When the translation of the stage has finished.
});
jQuery('.customNextBtn').click(function() {
owl.trigger('next.owl.carousel');
})
// Go to the previous item
jQuery('.customPrevBtn').click(function() {
// With optional speed parameter
// Parameters has to be in square bracket '[]'
owl.trigger('prev.owl.carousel', [300]);
})
function counter(event) {
var element = event.target; // DOM element, in this example .owl-carousel
var items = event.item.count; // Number of items
var item = event.item.index + 1; // Position of the current item
// it loop is true then reset counter from 1
if(item > items) {
item = item - items
}
jQuery(element).parent().find('.counter').html(item + " / " + items);
}
});
这里又是我的FIDDLE
我只需要让它们独立工作。它们在拖动图像时工作,但是当您使用箭头时,它只会移动所有滑块
我认为它与按钮点击有关,我猜它没有找到它的父 div
【问题讨论】:
-
在 owl carosel 的主 div 上添加 ID,例如:var owl = jQuery('#owl-carouselone'); var owltwo = jQuery('.owl-carouseltwo');
-
我不认为这是可以做到的,因为每个滑块都是使用 ACF 动态的,所以可能有两个以上,可能还有 10 个以上
-
你必须为每个 carousal 使用不同的 carousal 初始化器。在这里查看jsfiddle.net/97j9gmtm/2
标签: javascript jquery owl-carousel