Owl 当 `items` 是分数且 loop 为 false 时,轮播不会滑动下一个项目
Owl Carousel won't slide next item when `items` is a fraction AND loop is false
如果我将 items
属性 设置为分形数(例如:1.3),轮播无法使用鼠标拖动滑动。它"jumps"回到第一项。
使用点或导航效果很好。
$('.my-carousel').owlCarousel({
items: 1.3,
margin: 10
// If `loop` is set to `true`, this problem does not happen;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/owl.carousel.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.carousel.min.css">
<div class="my-carousel owl-carousel">
<div class="my-carousel__item">
<img src="//placehold.it/256x256/000000/cacaca/?text=1">
</div>
<div class="my-carousel__item">
<img src="//placehold.it/256x256/cacaca/000000/?text=2">
</div>
<div class="my-carousel__item">
<img src="//placehold.it/256x256/000000/cacaca/?text=3">
</div>
<div class="my-carousel__item">
<img src="//placehold.it/256x256/cacaca/000000/?text=4">
</div>
<div class="my-carousel__item">
<img src="//placehold.it/256x256/000000/cacaca/?text=5">
</div>
<div class="my-carousel__item">
<img src="//placehold.it/256x256/cacaca/000000/?text=6">
</div>
</div>
实际上,这是因为您在制作最后一张幻灯片时想到了这一点。当你在最后一张幻灯片上时会发生什么。 Owl 轮播不会在那里显示一半的项目,这会阻止它工作。
owl 轮播的上述方法在项目中使用分数不推荐。如果你想显示 1 个半项目,请使用
stagePadding: value
在 owl 轮播选项中。如果你只想在一侧填充,请使用下面的 CSS
工作示例
$('.my-carousel').owlCarousel({
items: 1,
margin: 10,
stagePadding: 100
});
.owl-carousel .owl-stage {
padding-left: 0 !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/owl.carousel.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.carousel.min.css">
<div class="my-carousel owl-carousel">
<div class="my-carousel__item">
<img src="//placehold.it/256x256/000000/cacaca/?text=1">
</div>
<div class="my-carousel__item">
<img src="//placehold.it/256x256/cacaca/000000/?text=2">
</div>
<div class="my-carousel__item">
<img src="//placehold.it/256x256/000000/cacaca/?text=3">
</div>
<div class="my-carousel__item">
<img src="//placehold.it/256x256/cacaca/000000/?text=4">
</div>
<div class="my-carousel__item">
<img src="//placehold.it/256x256/000000/cacaca/?text=5">
</div>
<div class="my-carousel__item">
<img src="//placehold.it/256x256/cacaca/000000/?text=6">
</div>
</div>
如果我将 items
属性 设置为分形数(例如:1.3),轮播无法使用鼠标拖动滑动。它"jumps"回到第一项。
使用点或导航效果很好。
$('.my-carousel').owlCarousel({
items: 1.3,
margin: 10
// If `loop` is set to `true`, this problem does not happen;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/owl.carousel.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.carousel.min.css">
<div class="my-carousel owl-carousel">
<div class="my-carousel__item">
<img src="//placehold.it/256x256/000000/cacaca/?text=1">
</div>
<div class="my-carousel__item">
<img src="//placehold.it/256x256/cacaca/000000/?text=2">
</div>
<div class="my-carousel__item">
<img src="//placehold.it/256x256/000000/cacaca/?text=3">
</div>
<div class="my-carousel__item">
<img src="//placehold.it/256x256/cacaca/000000/?text=4">
</div>
<div class="my-carousel__item">
<img src="//placehold.it/256x256/000000/cacaca/?text=5">
</div>
<div class="my-carousel__item">
<img src="//placehold.it/256x256/cacaca/000000/?text=6">
</div>
</div>
实际上,这是因为您在制作最后一张幻灯片时想到了这一点。当你在最后一张幻灯片上时会发生什么。 Owl 轮播不会在那里显示一半的项目,这会阻止它工作。 owl 轮播的上述方法在项目中使用分数不推荐。如果你想显示 1 个半项目,请使用
stagePadding: value
在 owl 轮播选项中。如果你只想在一侧填充,请使用下面的 CSS
工作示例
$('.my-carousel').owlCarousel({
items: 1,
margin: 10,
stagePadding: 100
});
.owl-carousel .owl-stage {
padding-left: 0 !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/owl.carousel.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.carousel.min.css">
<div class="my-carousel owl-carousel">
<div class="my-carousel__item">
<img src="//placehold.it/256x256/000000/cacaca/?text=1">
</div>
<div class="my-carousel__item">
<img src="//placehold.it/256x256/cacaca/000000/?text=2">
</div>
<div class="my-carousel__item">
<img src="//placehold.it/256x256/000000/cacaca/?text=3">
</div>
<div class="my-carousel__item">
<img src="//placehold.it/256x256/cacaca/000000/?text=4">
</div>
<div class="my-carousel__item">
<img src="//placehold.it/256x256/000000/cacaca/?text=5">
</div>
<div class="my-carousel__item">
<img src="//placehold.it/256x256/cacaca/000000/?text=6">
</div>
</div>