gpt4 book ai didi

javascript - 如何在 Owl Carousel 中只显示单个项目?

转载 作者:行者123 更新时间:2023-11-29 22:44:04 27 4
gpt4 key购买 nike

所以我在我的项目中使用 ngx-owl-carousel 来显示幻灯片,这些幻灯片将显示来自 REST API 的动态数据。当数据量很大时,轮播可以正常工作。但是如果只有一个数据旋转木马根据屏幕宽度显示重复的幻灯片,而不仅仅是一张。如何修复这是我设置的轮播属性:

carouselOptions = {

autoplay:false,
autoplayTimeout:3000,
autoplayHoverPause:false,
autoWidth:false,
items:1,
singleItem: true,
loop:true,
nav: true,
navText: ["<i aria-hidden='true' class='fa fa-caret-left prev' id='prev'></i>","<i aria-hidden='true' class='fa fa-caret-right next'></i>"],
navClass: ['owl-prev', 'owl-next'],
responsiveClass: true,
responsive: {
0:{
items:1,
nav:true,
dots:false
},
576: {
items: 1,
nav: true,
dots:false
},
768: {
items: 2,
nav: true
},
1050: {
items: 3,
nav: true

},
1400: {
items: 4,
nav: true
}
}

这是我的 html:

<owl-carousel [options]="carouselOptions" [items]="userData"
[carouselClasses]="['owl-theme', 'row', 'sliding']">
<div class="item mt-4" id="item" *ngFor="let data of userData;let i = index">
<div class="card-body">
<div class="card-title mb-0 random" >
<div class="title">
<div class="user-info">
<div>{{data.name}}</div>&nbsp;&nbsp;|&nbsp;&nbsp;
<p>{{data.contact}}</p>
</div>
<div class="setting-icon">
<i class="fa fa-cog"></i>
</div>
</div>
</div>
<div class="after-title pt-3">
<div class="p-2">
<h6 class="card-subtitle text-muted">
<div class="subtitle"> <i class="fa fa-edit"></i><i class="fa fa-expand"></i></div>
</h6>
<p class="card-text main-card-text" id="notes">{{ data.message }}</p>
</div>
<div class="footer">
<i class="fa fa-paperclip pt-1 pl-2"></i> &nbsp; &nbsp;
<i class="fa fa-lock pt-1"></i>&nbsp; &nbsp;
<i class="fa fa-hand-rock-o pt-1"></i>&nbsp; &nbsp;
<i class="fa fa-save pt-1"></i>
</div>
</div>
</div>
</div>
</owl-carousel>

这是我得到的输出:正如您所看到的,当 userData 数组中只有一个项目时,幻灯片会重复播放。 enter image description here

最佳答案

你可以使用 loop:false 这样它就不会产生重复的项目。

希望对你有帮助

$('.with-loop').owlCarousel({
loop:true,
margin:10,
nav:true,
responsive:{
0:{
items:3
},
600:{
items:3
},
1000:{
items:5
}
}
})

$('.without-loop').owlCarousel({
loop:false,
margin:10,
nav:true,
responsive:{
0:{
items:3
},
600:{
items:3
},
1000:{
items:5
}
}
})
.with-loop {
margin-bottom: 30px;
}
.item {
height: 30px;
width: 40px;
background: red;
color: #fff;
text-align: center
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://owlcarousel2.github.io/OwlCarousel2/assets/owlcarousel/owl.carousel.js"></script>
<link rel="stylesheet" href="https://owlcarousel2.github.io/OwlCarousel2/assets/owlcarousel/assets/owl.carousel.min.css" />
<link rel="stylesheet" href="https://owlcarousel2.github.io/OwlCarousel2/assets/owlcarousel/assets/owl.theme.default.min.css" />
<div class="owl-carousel owl-theme with-loop">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
</div>


<div class="owl-carousel owl-theme without-loop">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
</div>

关于javascript - 如何在 Owl Carousel 中只显示单个项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59155012/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com