javascript - Bootstrap 3 Multi Item Carousel 一次只显示一个项目
问题描述
我试图从这里创建一个多项目轮播。
在这里它看起来很完美,因为我希望它能够工作。但是当我将此代码带到我的工作区时,它一次只显示一个项目,其余的地方保持空白。这是它在我的机器上的样子:
理想情况下,它应该一次显示 4 个项目并逐个滚动 1。但它只显示 1 个项目,其他 3 个项目的位置保持为空。你能建议我在这里错过什么吗?
$('.carousel[data-type="multi"] .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));
}
});
.col-centered {
float: none;
margin: 0 auto;
}
.carousel-control {
width: 8%;
width: 0px;
}
.carousel-control.left,
.carousel-control.right {
margin-right: 40px;
margin-left: 32px;
background-image: none;
opacity: 1;
}
.carousel-control > a > span {
color: white;
font-size: 29px !important;
}
.carousel-col {
position: relative;
min-height: 1px;
padding: 5px;
float: left;
}
.active > div { display:none; }
.active > div:first-child { display:block; }
/*xs*/
@media (max-width: 767px) {
.carousel-inner .active.left { left: -50%; }
.carousel-inner .active.right { left: 50%; }
.carousel-inner .next { left: 50%; }
.carousel-inner .prev { left: -50%; }
.carousel-col { width: 50%; }
.active > div:first-child + div { display:block; }
}
/*sm*/
@media (min-width: 768px) and (max-width: 991px) {
.carousel-inner .active.left { left: -50%; }
.carousel-inner .active.right { left: 50%; }
.carousel-inner .next { left: 50%; }
.carousel-inner .prev { left: -50%; }
.carousel-col { width: 50%; }
.active > div:first-child + div { display:block; }
}
/*md*/
@media (min-width: 992px) and (max-width: 1199px) {
.carousel-inner .active.left { left: -33%; }
.carousel-inner .active.right { left: 33%; }
.carousel-inner .next { left: 33%; }
.carousel-inner .prev { left: -33%; }
.carousel-col { width: 33%; }
.active > div:first-child + div { display:block; }
.active > div:first-child + div + div { display:block; }
}
/*lg*/
@media (min-width: 1200px) {
.carousel-inner .active.left { left: -25%; }
.carousel-inner .active.right{ left: 25%; }
.carousel-inner .next { left: 25%; }
.carousel-inner .prev { left: -25%; }
.carousel-col { width: 25%; }
.active > div:first-child + div { display:block; }
.active > div:first-child + div + div { display:block; }
.active > div:first-child + div + div + div { display:block; }
}
.block {
width: 306px;
height: 230px;
}
.red {background: red;}
.blue {background: blue;}
.green {background: green;}
.yellow {background: yellow;}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-xs-11 col-md-10 col-centered">
<div id="carousel" class="carousel slide" data-ride="carousel" data-type="multi" data-interval="2500">
<div class="carousel-inner">
<div class="item active">
<div class="carousel-col">
<div class="block red img-responsive"></div>
</div>
</div>
<div class="item">
<div class="carousel-col">
<div class="block green img-responsive"></div>
</div>
</div>
<div class="item">
<div class="carousel-col">
<div class="block blue img-responsive"></div>
</div>
</div>
<div class="item">
<div class="carousel-col">
<div class="block yellow img-responsive"></div>
</div>
</div>
</div>
<!-- Controls -->
<div class="left carousel-control">
<a href="#carousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
</div>
<div class="right carousel-control">
<a href="#carousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</div>
</div>
</div>
</body>
解决方案
推荐阅读
- amazon-web-services - 在 Fn::Transform 中使用 FindInMap 作为位置参数
- google-cloud-run - 如何为 GKE 上部署的 Google Cloud Run 服务增加 15 分钟的请求超时?
- ruby-on-rails - ActiveRecord:如何在使用 left_join 时取消 default_scope 的范围?
- c - C中的信号量死锁
- c++ - 多线程未按预期运行
- docker - 加快 'apt-get update' 以加快 Docker 映像构建
- c# - 控制器的非异步方法是否会阻止其他用户在使用或锁定时进入?
- f# - 如何在 F# 中使用 C# 可为空的日期时间
- c++ - CMake 找不到 boost_test
- python - 如何将函数中的值设置为 CSV?