我正在使用owl carousel 2插件来显示滑块。它可以在静态模式下工作,但是如何设置动态模式呢?
我的意思是,手动设置3会得到3个滑块,但是如何动态设置呢?在$ getTotalnumber中,我从数据库中获取记录。有时我会获得总记录2,3和4,那么我该如何重复该项目?现在,我从数据库中获得2条记录,而滑块显示3条记录正在重复。第一项重复。
<div class="owl-carousel owl-theme">
<?php if($getTotalnumber){foreach ($getTotalnumber as $num) {?>
<div class="item"><h4><?php echo $num->content;?>></h4></div>
<?php }}?>
</div>
$('.owl-carousel').owlCarousel({
loop: true,
margin: 10,
nav: true,
mouseDrag: false,
responsive: {
0: {
items: 1
},
600: {
items: 3
},
1000: {
items: 3
}
}
});
我正在获取输出(文本只是一个示例)
where are you?
How are you?
Where are you?// notice that this is repeating from first one
我需要一个输出
where are you?
How are you?
答案 0 :(得分:1)
所以您只需要提及在Owl Carousel配置中显示多少个项目:
<?php
if (!empty($getTotalnumber)) { ?>
$('.owl-carousel').owlCarousel({
loop: true,
margin: 10,
nav: true,
mouseDrag: false,
responsive: {
0: {
items: 1
},
600: {
items: <?php echo count($getTotalnumber); ?>
},
1000: {
items: <?php echo count($getTotalnumber); ?>
}
}
});
<?php } ?>