gpt4 book ai didi

javascript - 传送带上每个四个项目不工作

转载 作者:行者123 更新时间:2023-12-03 01:56:21 25 4
gpt4 key购买 nike

当我在本地文件中尝试以下代码时,我无法正确获取它,请参阅代码笔 4 items per Carousel 。我已在问题中插入了代码。请看下面

我只想为每个轮播制作 4 个项目,单击“下一步”,应添加一个项目

请看下面的代码,我需要它是水平的而不是垂直的

$(document).ready(function(){

$('#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));

for (var i=0;i<2;i++) {
next=next.next();
if (!next.length) {
next = $(this).siblings(':first');
}

next.children(':first-child').clone().appendTo($(this));
}
});

})
.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);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>

<div class="container text-center my-3">
<div class="row mx-auto my-auto">
<div id="recipeCarousel" class="carousel slide w-100" data-ride="carousel">
<div class="carousel-inner" role="listbox">
<div class="carousel-item active">
<img class="d-block col-3 img-fluid" src="http://placehold.it/350x180?text=1">
</div>
<div class="carousel-item">
<img class="d-block col-3 img-fluid" src="http://placehold.it/350x180?text=2">
</div>
<div class="carousel-item">
<img class="d-block col-3 img-fluid" src="http://placehold.it/350x180?text=3">
</div>
<div class="carousel-item">
<img class="d-block col-3 img-fluid" src="http://placehold.it/350x180?text=4">
</div>
<div class="carousel-item">
<img class="d-block col-3 img-fluid" src="http://placehold.it/350x180?text=5">
</div>
<div class="carousel-item">
<img class="d-block col-3 img-fluid" src="http://placehold.it/350x180?text=6">
</div>
</div>
<a class="carousel-control-prev" href="#recipeCarousel" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#recipeCarousel" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
<h4>Advances one slide at a time</h4>
</div>

最佳答案

添加下面的CSS并检查

  .carousel-inner .img-fluid{
float: left;
}

关于javascript - 传送带上每个四个项目不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50211795/

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