Bootstrap 4 Carousel 一次多帧,逐帧滑动
Bootstrap 4 Carousel Multiple frames at once and slide by one
针对 bootstrap 3 的相同需求 (that question) 提出了另一个问题,但建议的解决方案不适用于 Bootstrap 4。
这个post的形象很好的诠释了我想要的。
还有更多this bootply。
如何使用 Bootstrap 4 实现此目的?
2018 年更新
查看 Bootstrap 4 docs,并将标记更改为 Bootstrap 4:
Bootstrap 4 Beta 选项:
$('#carousel-example-generic').on('slid.bs.carousel', function () {
$(".carousel-item.active:nth-child(" + ($(".carousel-inner .carousel-item").length -1) + ") + .carousel-item").insertBefore($(".carousel-item:first-child"));
$(".carousel-item.active:last-child").insertBefore($(".carousel-item:first-child"));
});
.carousel-item.active,
.carousel-item.active + .carousel-item,
.carousel-item.active + .carousel-item + .carousel-item {
width: 33.3%;
display: block;
float:left;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css" rel="stylesheet"/>
<h1>Hello, world!</h1>
<div class="container">
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
<li data-target="#carousel-example-generic" data-slide-to="2"></li>
</ol>
<div class="carousel-inner" role="listbox">
<div class="carousel-item active">
<img data-src="holder.js/300x200?text=1">
</div>
<div class="carousel-item">
<img data-src="holder.js/300x200?text=2">
</div>
<div class="carousel-item">
<img data-src="holder.js/300x200?text=3">
</div>
<div class="carousel-item">
<img data-src="holder.js/300x200?text=4">
</div>
<div class="carousel-item">
<img data-src="holder.js/300x200?text=5">
</div>
<div class="carousel-item">
<img data-src="holder.js/300x200?text=6">
</div>
<div class="carousel-item">
<img data-src="holder.js/300x200?text=7">
</div>
</div>
<a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
<span class="icon-prev" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
<span class="icon-next" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/holder/2.9.1/holder.min.js"></script>
针对 bootstrap 3 的相同需求 (that question) 提出了另一个问题,但建议的解决方案不适用于 Bootstrap 4。
这个post的形象很好的诠释了我想要的。
还有更多this bootply。
如何使用 Bootstrap 4 实现此目的?
2018 年更新
查看 Bootstrap 4 docs,并将标记更改为 Bootstrap 4:
Bootstrap 4 Beta 选项:
$('#carousel-example-generic').on('slid.bs.carousel', function () {
$(".carousel-item.active:nth-child(" + ($(".carousel-inner .carousel-item").length -1) + ") + .carousel-item").insertBefore($(".carousel-item:first-child"));
$(".carousel-item.active:last-child").insertBefore($(".carousel-item:first-child"));
});
.carousel-item.active,
.carousel-item.active + .carousel-item,
.carousel-item.active + .carousel-item + .carousel-item {
width: 33.3%;
display: block;
float:left;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css" rel="stylesheet"/>
<h1>Hello, world!</h1>
<div class="container">
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
<li data-target="#carousel-example-generic" data-slide-to="2"></li>
</ol>
<div class="carousel-inner" role="listbox">
<div class="carousel-item active">
<img data-src="holder.js/300x200?text=1">
</div>
<div class="carousel-item">
<img data-src="holder.js/300x200?text=2">
</div>
<div class="carousel-item">
<img data-src="holder.js/300x200?text=3">
</div>
<div class="carousel-item">
<img data-src="holder.js/300x200?text=4">
</div>
<div class="carousel-item">
<img data-src="holder.js/300x200?text=5">
</div>
<div class="carousel-item">
<img data-src="holder.js/300x200?text=6">
</div>
<div class="carousel-item">
<img data-src="holder.js/300x200?text=7">
</div>
</div>
<a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
<span class="icon-prev" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
<span class="icon-next" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/holder/2.9.1/holder.min.js"></script>