更改Bootstrap Carousel淡入淡出过渡

cl25kdpy  于 2023-09-28  发布在  Bootstrap
关注(0)|答案(4)|浏览(147)

在Stackoverflow上有几个关于Carousel渐变的问题,但它们似乎都不适用于默认的4.0.0实现:

<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="..." alt="First slide">
    </div>
    <div class="carousel-item">
      <img class="d-block w-100" src="..." alt="Second slide">
    </div>
    <div class="carousel-item">
      <img class="d-block w-100" src="..." 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>

自Alpha.6版本以来,bootstrap是否改变了转换carousel-item-s的方式?如何在4.0.0中实现渐变而不是幻灯片?

fdbelqdn

fdbelqdn1#

Bootstrap 5 Carousel Fade(2021年更新)

Bootstrap 5包含一个“渐变”效果,只需将carousel-fade类添加到Carousel即可使用。默认情况下,过渡持续时间为.6s。若要增加持续时间并使幻灯片之间的淡入淡出变慢,请覆盖CSS上的过渡计时...

/* change transition duration to control the speed of fade effect */
.carousel-item {
  transition: transform 2.6s ease-in-out;
}

.carousel-fade .active.carousel-item-start,
.carousel-fade .active.carousel-item-end {
  transition: opacity 0s 2.6s;
}

Bootstrap 5 Carousel淡入淡出较慢

Bootstrap 4.0 Carnival Fade(原始答案)

.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);
}

淡入淡出效果在4.0 Beta版中从轮播中删除,在4.0.0中也不可用。此pull request表示渐变效果将在4.1或4.2中返回。同时,上述CSS将适用于4.0.0
https://codeply.com/go/LhLJlldsLN

iyfjxgzm

iyfjxgzm2#

为了获得淡入效果,您可以在carousel的主div中添加**“carousel-fade”**类,如下所示。
更新:Bootstrap 5
Bootstrap 5与Bootstrap 4几乎相同,但data-ride属性现在是data-bs-ride
Bootstrap 5示例

<div id="carouselExampleIndicators" class="carousel slide carousel-fade" data-bs-ride="carousel">
...
</div>

Bootstrap 4示例

<div id="carouselExampleIndicators" class="carousel slide carousel-fade" data-ride="carousel"> 
....
</div>
hzbexzde

hzbexzde4#

在bootstrap 4中,你可以像这样添加“slide-fade”类:

<div id="carouselExampleIndicators" class="carousel slide-fade" data-ride="carousel">....</div>

相关问题