Owl Carousel 2 - autoHeight (multiple items)
At the moment the Owl Carousel autoHeight works only with 1 item on screen. Their plan is to calculate all visible items and change height according to highest item. I work around this problem by calling the .active classes on the visible items, and give the invisible items a small height. Is there already a more elegant solution?
by Schakelen
HTML
<script src="https://rawgit.com/OwlFonk/OwlCarousel2/develop/src/js/owl.carousel.js"></script>
<link rel="stylesheet" href="https://cdn.rawgit.com/OwlFonk/OwlCarousel2/develop/src/css/owl.theme.default.css">
<link rel="stylesheet" href="https://rawgit.com/OwlFonk/OwlCarousel2/develop/src/css/owl.carousel.css">
<div class="owl-carousel">
<div class="item" style="height:100px;">
1
</div>
<div class="item" style="height:150px;">
2
</div>
<div class="item" style="height:200px;">
3
</div>
<div class="item" style="height:250px;">
4
</div>
<div class="item" style="height:300px;">
5
</div>
<div class="item" style="height:350px;">
6
</div>
<div class="item" style="height:400px;">
7
</div>
<div class="item" style="height:450px;">
8
</div>
</div>
<a class="prev">prev</a>
<a class="next">next</a>
CSS
.owl-carousel .owl-item {
background:#CCC;
padding:20px;
box-sizing: border-box;
-o-box-sizing: border-box;
-ms-box-sizing: border-box;
-moz-box-sizing: border-box;
-khtml-box-sizing: border-box;
-webkit-box-sizing: border-box;
}
JavaScript
$('.owl-carousel').owlCarousel({
loop: true,
items: 3,
margin: 1,
autoHeight: true,
});
owl = $('.owl-carousel').owlCarousel();
$(".prev").click(function () {
owl.trigger('prev.owl.carousel');
});
$(".next").click(function () {
owl.trigger('next.owl.carousel');
});