Last active
August 29, 2015 14:05
-
-
Save jrosczyk/322f45054862fbe4e6fa to your computer and use it in GitHub Desktop.
check for lonely slide - owl carousel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(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" ); | |
| } | |
| }); |
Author
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
Revision 2: adds randomizer