2015-02-02 20 views
5

Có cách nào trong Owl Carousel 2 thực hiện một chức năng ngẫu nhiên của vua hay không. Tôi cần các trang trình bày trên trang để tải ngẫu nhiên.Owl Carousel 2 chức năng ngẫu nhiên

Trước khi trong phiên bản Owl Carousel cũ tôi đã làm nó theo cách này:

$(document).ready(function() { 

    //Sort random function 
    function random(owlSelector) { 
     owlSelector.children().sort(function() { 
      return Math.round(Math.random()) - 0.5; 
     }).each(function() { 
      $(this).appendTo(owlSelector); 
     }); 
    } 

    $(".feedback").owlCarousel({ 
     autoPlay: 5000, 
     slideSpeed: 200, 
     items: 1, 
     itemsDesktop: [1199, 1], 
     itemsDesktopSmall: [979, 1], 
     itemsTablet: [768, 1], 
     itemsMobile: [479, 1], 
     autoHeight: true, 

     //Call beforeInit callback, elem parameter point to $(".feedback") 
     beforeInit: function (elem) { 
      random(elem); 
     } 
    }); 
}); 

Làm thế nào điều này có thể được thực hiện một cách tốt nhất trong Owl Carousel 2?

Trả lời

13

Bạn phải sử dụng các onInitialize callback mới, như thế này:

var owl = $('.owl-carousel'); 
owl.owlCarousel({ 
    onInitialize : function(element){ 
     owl.children().sort(function(){ 
      return Math.round(Math.random()) - 0.5; 
     }).each(function(){ 
      $(this).appendTo(owl); 
     }); 
    }, 
}); 

Tìm thêm thông tin trong 2.x docs.

+0

đã làm việc cho tôi, cảm ơn bạn. –

+0

Tôi có thể thêm cài đặt của mình bằng cách nào? –

+0

làm việc cho tôi, cảm ơn! – Bhavik

Các vấn đề liên quan