Bootstrap 3 Carousel randomize item (Snippet)

$('#myCarousel.carousel[data-type="multi"] .item').each(function(){

  $('#myCarousel.carousel[data-type="multi"] .item').removeClass('active').eq(Math.floor((Math.random() * $('#myCarousel.carousel[data-type="multi"] .item').length))).addClass("active");    
  var next = $(this).next();
  
    
  if (!next.length) {
    next = $(this).siblings(':first');
  }
  next.children(':first-child').clone().appendTo($(this));
  
  for (var i=0;i<4;i++) {
    next=next.next();
    if (!next.length) {
        next = $(this).siblings(':first');
  	}
    
    next.children(':first-child').clone().appendTo($(this));
  }
});


Leave a Reply

Your email address will not be published. Required fields are marked *