2015-02-02 3 views
5

C'è un modo in Owl Carousel 2 di fare una funzione casuale re. Ho bisogno che le diapositive sulla pagina vengano caricate casualmente.Owl Carousel 2 funzione casuale

Prima nella vecchia versione Gufo Carosello ho fatto in questo modo:

$(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); 
     } 
    }); 
}); 

Come può questo essere fatto nel migliore dei modi in Owl Carousel 2?

risposta

13

si deve utilizzare il nuovo onInitialize richiamata, in questo modo:

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); 
     }); 
    }, 
}); 

Trova maggiori informazioni nel 2.x docs.

+0

ha funzionato per me, grazie. –

+0

come posso aggiungere le mie impostazioni? –

+0

lavoro per me, grazie! – Bhavik