【问题标题】:How to slide 2 Owl carousels with one navigation如何通过一个导航滑动 2 个 Owl 旋转木马
【发布时间】:2019-01-17 19:06:56
【问题描述】:

我正在使用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 提供解决方案?

【问题讨论】:

    标签: jquery css owl-carousel


    【解决方案1】:

    我认为您需要编写单独的 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
         });
     });
    

    请检查我创建的小提琴。

    JS Fiddle

    【讨论】:

    • 感谢您的回复,我知道这个解决方案,但我需要所有导航类型来滑动这两个内容。这仅适用于上一个/下一个。
    • 就是这样。感谢您的帮助!
    • @ProblemChild 如何在拖动和 owl-dot 点击时自定义相同的东西。
    • @Sharvan 请使用 codepen 链接查看我上面的评论。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-12
    • 2017-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-18
    相关资源
    最近更新 更多