bootstrap轮播图案例
时间: 2023-07-05 07:36:23 浏览: 193
javaweb
Bootstrap提供了一个非常简单易用的轮播图组件,可以用来展示多个图片或者内容。下面是一个轮播图的示例代码:
HTML代码:
```
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
<img class="d-block w-100" src="img1.jpg" alt="First slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="img2.jpg" alt="Second slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="img3.jpg" alt="Third slide">
</div>
</div>
<a class="carousel-control-prev" href="#carouselExampleIndicators" 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="#carouselExampleIndicators" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
```
CSS代码:
```
.carousel-item {
height: 400px;
}
.carousel-item img {
height: 100%;
width: 100%;
object-fit: cover;
}
```
JavaScript代码:
```
$('.carousel').carousel({
interval: 2000
})
```
以上代码实现了一个简单的 Bootstrap 轮播图效果,你可以根据自己的需求进行修改和扩展。
阅读全文