Skip to content

Instantly share code, notes, and snippets.

@jrosczyk
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save jrosczyk/322f45054862fbe4e6fa to your computer and use it in GitHub Desktop.

Select an option

Save jrosczyk/322f45054862fbe4e6fa to your computer and use it in GitHub Desktop.
check for lonely slide - owl carousel
$(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);
});
}
//Set slide location
$owl = $("#slides");
$owlSlides = $owl.children('div');
//Check for single slide
if($owlSlides.length > 1) {
//Set carousel
$owl.owlCarousel({
autoPlay : 5000,
stopOnHover : true,
navigation:true,
paginationSpeed : 1000,
goToFirstSpeed : 2000,
singleItem : true,
autoHeight : true,
lazyLoad : true,
transitionStyle:"fade",
beforeInit : function(elem){
random(elem);
}
});
//Stop carousel on page click
$(".owl-page").click(function(){
$owl.trigger('owl.stop');
});
} else {
//Remove carousel class
$owl.removeClass( "owl-carousel" );
}
});
@jrosczyk

Copy link
Copy Markdown
Author

Revision 2: adds randomizer

@jrosczyk

Copy link
Copy Markdown
Author

Revision 3: add stop trigger to carousel upon clicking on pagination links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment