2017-11-11 167 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