我想不出如何让它显示4张图片而不是3张。
Based on this Code: Bootstrap 4 Multiple Item Carousel
脚本JS
$('#recipeCarousel').carousel({
interval: 10000
})
$('.carousel .carousel-item').each(function(){
var next = $(this).next();
if (!next.length) {
next = $(this).siblings(':first');
}
next.children(':first-child').clone().appendTo($(this));
if (next.next().length>0) {
next.next().children(':first-child').clone().appendTo($(this));
}
else {
$(this).siblings(':first').children(':first-child').clone().appendTo($(this));
}
});CSS
.carousel-inner .carousel-item-right.active,
.carousel-inner .carousel-item-next {
transform: translateX(25%);
}
.carousel-inner .carousel-item-left.active,
.carousel-inner .carousel-item-prev {
transform: translateX(-25%)
}
.carousel-inner .carousel-item-right,
.carousel-inner .carousel-item-left{
transform: translateX(0);
}我已经改成了下面的代码
<div class="carousel-item col-md-3">而不是这个原始代码
<div class="carousel-item col-md-4">发布于 2018-02-06 05:17:51
由于4个cols的宽度为25% (而不是33%),因此更改CSS:
.carousel-inner .carousel-item-right.active,
.carousel-inner .carousel-item-next {
transform: translateX(25%);
}
.carousel-inner .carousel-item-left.active,
.carousel-inner .carousel-item-prev {
transform: translateX(-25%)
}此外,还需要在每张幻灯片中克隆一个额外的项目。所以JS的变化是:
$('.carousel .carousel-item').each(function(){
var next = $(this).next();
if (!next.length) {
next = $(this).siblings(':first');
}
next.children(':first-child').clone().appendTo($(this));
for (var i=0;i<2;i++) {
next=next.next();
if (!next.length) {
next = $(this).siblings(':first');
}
next.children(':first-child').clone().appendTo($(this));
}
});Bootstrap 4.0.0 Demo - 4 slides, advance 1
注意:从Alpha6(当最初的问题被问到时)到flexbox Bootstrap 4.0.0,活动的carousel-item更改为。因此,必须对多轮播中的相邻项执行相同的操作。
.carousel-inner .carousel-item.active,
.carousel-inner .carousel-item-next,
.carousel-inner .carousel-item-prev {
display: flex;
}https://stackoverflow.com/questions/48631386
复制相似问题