|
|
|
|
|
Bootstrap 4 Carousel 的幻燈片默認(rèn)是滑動(dòng)過渡的,如果你想更改為淡入淡出過渡,那么可以參考下本文介紹的方法。
為此,我們需要對(duì) HTML 代碼進(jìn)行的唯一更改是將類添加carousel-fade
到主輪播 div
。在我們的示例中,它是帶有 ID 元素的 div
my-carousel
。接下來,我們只需復(fù)制并粘貼下面的 CSS 代碼,就可以了!
HTML
<div id="my-carousel" class="carousel slide carousel-fade" data-ride="carousel" data-interval="5000">
<ol class="carousel-indicators">
<li data-target="#my-carousel" data-slide-to="0" class="active"></li>
<li data-target="#my-carousel" data-slide-to="1"></li>
<li data-target="#my-carousel" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
<img class="d-block w-100" src="1.jpg" alt="First slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="2.jpg" alt="Second slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="3.jpg" alt="Third slide">
</div>
</div>
<a class="carousel-control-prev" href="#my-carousel" 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="#my-carousel" 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-fade .carousel-item {
opacity: 0;
transition-duration: .6s;
transition-property: opacity;
}
.carousel-fade .carousel-item.active,
.carousel-fade .carousel-item-next.carousel-item-left,
.carousel-fade .carousel-item-prev.carousel-item-right {
opacity: 1;
}
.carousel-fade .active.carousel-item-left,
.carousel-fade .active.carousel-item-right {
opacity: 0;
}
.carousel-fade .carousel-item-next,
.carousel-fade .carousel-item-prev,
.carousel-fade .carousel-item.active,
.carousel-fade .active.carousel-item-left,
.carousel-fade .active.carousel-item-prev {
transform: translateX(0);
transform: translate3d(0, 0, 0);
}
很簡(jiǎn)單吧,希望這對(duì)你有所幫助!