2017-11-11 166 views
4

所以导航,我使用这个https://codepen.io/desandro/pen/wByaqjFlickity转盘为另一个

我激活了prevNextButtons: true,这样的:

$('.characters-main').flickity({ 
     prevNextButtons: false, 
     wrapAround: false, 
     pageDots: false, 
     autoPlay: 10000 
    }); 
    $('.characters-nav').flickity({ 
     asNavFor: '.characters-main', 
     cellAlign: 'right', 
     prevNextButtons: true, 
     contain: true, 
     pageDots: false, 
     arrowShape: { 
     x0: 10, 
     x1: 70, y1: 50, 
     x2: 70, y2: 50, 
     x3: 35 
     } 
    }); 

我想,当我点击prevNextButtons.characters-nav自动从.characters-main中选择元素。

这是它是如何工作现在:

enter image description here

+0

它会更好,如果你分享与你的工作通过小提琴或codepen。 – mlbd

+0

分享您的HTML代码 –

回答

3

我已经采取Your Example over here,我已经添加以下代码:

// Main div 
    var flkty = new Flickity('.carousel-main'); 

    // Next and previous events of the navigation div 
    $(".carousel-nav .next").on("click", function() { 
      // Changing items of the main div 
      flkty.next(); 
    }); 



$(".carousel-nav .previous").on("click", function() { 
      // Changing items of the main div 
      flkty.previous(); 
    }); 

在你的情况应该是这样的:

  // Your main div is characters-main 
     var flkty = new Flickity('.characters-main'); 

     // Next and previous events of the characters-nav 
     $(".characters-nav .next").on("click", function() { 
       // Changing items of the main div 
       flkty.next(); 
     }); 



    $(".characters-nav .previous").on("click", function() { 
       // Changing items of the main div 
       flkty.previous(); 
     }); 
+0

这实际上起作用了,我还通过激活''.characters-main''上的''prevNextButtons''和编辑css中的按钮位置来找到解决方法。 – LuTz

1

请尝试使用下面的代码。我用flickity事件'select'。你也可以尝试解决。

var $carousel2 = $('.characters-main').flickity({ 
    prevNextButtons: false, 
    wrapAround: false, 
    pageDots: false, 
    autoPlay: 10000 
}); 

var $carousel = $('.characters-nav').flickity({ 
    asNavFor: '.characters-main', 
    cellAlign: 'right', 
    prevNextButtons: true, 
    contain: true, 
    pageDots: false, 
    arrowShape: { 
     x0: 10, 
     x1: 70, y1: 50, 
     x2: 70, y2: 50, 
     x3: 35 
    } 
}); 
$carousel.on('select.flickity', function(event, pointer, cellElement, cellIndex) { 
    if (typeof cellIndex == 'number') { 
     $carousel2.flickity('select', cellIndex); 
    } 
}); 
+0

它不起作用。当我使用箭头按钮导航时,波纹管不会改变。这是问题,请参阅gif。 – LuTz