Owl Carousal2 with 1 elements and loop true
$(document).ready(function(){
$('.owl-carousel').owlCarousel({
loop:true,
margin:10,
nav:true,
items: 1
})
});
<div class="owl-carousel">
<div class="item"><h4>1</h4></div>
</div>
<link href="http://www.owlcarousel.owlgraphic.com/assets/owlcarousel/assets/owl.carousel.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://www.owlcarousel.owlgraphic.com/assets/owlcarousel/owl.carousel.js"></script>
Console error: TypeError: items [clones [(clones.length - 1)]] undefined.
this error is due to only one element div
and property loop true
and point 1. So. any solution in this situation. I know this type of situation does not arise, but if any solutions please tell me thanks.
+5
source to share
8 answers
Add onInitialize and check how many items the carousel contains. If the carousel has 1 or fewer items, set the loop to false.
$(document).ready(function(){
$('.owl-carousel').owlCarousel({
loop:true,
margin:10,
nav:true,
items: 1,
onInitialize: function (event) {
if ($('.owl-carousel .item').length <= 1) {
this.settings.loop = false;
}
}
})
});
+13
source to share
I made a very basic fix (in owl.carousel.js file). Check out my comment here https://github.com/OwlCarousel2/OwlCarousel2/issues/1200#issuecomment-215254526
This is a very quick and dirty fix. This I will try to improve as soon as I can.
+1
source to share