在我的主页中,我使用了一个JavaScript轮播函数,即owl carousel。但是,我的主页上只有五个轮播。我想要的是修改JavaScript,以便可以将每个轮播放在要显示的项目数上。这是我的JavaScript:
$(document).ready(function() {
$(".owl-carousel").owlCarousel(
{
autoplay: true,
autoplayHoverPause: true,
loop: true,
margin:2,
autoplayTimeout: 2000,
autoplayHoverPause: true,
responsiveClass: true,
loop: true,
responsive: {
0: {
items: 1
},
568: {
items: 2
},
600: {
items: 3
},
1000: {
items: 4
}
}
});
答案 0 :(得分:0)
如果我正确理解了您的问题,那么您应该这样做:
const carousels = document.querySelectorAll('.owl-carousel');
carousels.forEach((carousel) => {
$(carousel).owlCarousel({
autoplay: true,
autoplayHoverPause: true,
loop: true,
margin: 2,
autoplayTimeout: 2000,
autoplayHoverPause: true,
responsiveClass: true,
loop: true,
responsive: {
0: {
items: 1,
},
568: {
items: 2,
},
600: {
items: 3,
},
1000: {
items: 4,
},
},
});
});