Bootstrap 4.0.0 Carousel淡入淡出过渡

时间:2018-02-07 13:44:05

标签: css twitter-bootstrap bootstrap-4

关于Carousel淡入淡出转换,Stackoverflow上有几个问题,但它们似乎都不适用于默认的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版以来,引导程序是否改变了转换carousel-item -s的方式?如何实现淡入淡出过渡而不是4.0.0中的幻灯片?

4 个答案:

答案 0 :(得分:16)

我重新打开了这个,因为问题从4 Beta变为4.0.0(稳定)......

Bootstrap 4.0.0 Carousel Fade:
https://www.codeply.com/go/LhLJlldsLN

.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

答案 1 :(得分:9)

在bootstrap 4中,您可以像这样添加“carousel-fade”类。

class Employee {
int empId;
String empName;

public Employee() {
}

Employee(int empId, String empName) {
    this.empId = empId;
    this.empName = empName;
}

public int getEmpId() {
    return empId;
}

public void setEmpId(int empId) {
    this.empId = empId;
}

public String getEmpName() {
    return empName;
}

public void setEmpName(String empName) {
    this.empName = empName;
}

@Override
public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + empId;
    result = prime * result + ((empName == null) ? 0 : empName.hashCode());
    return result;
}

@Override
public boolean equals(Object obj) {
    if (this == obj)
        return true;
    if (obj == null)
        return false;
    if (getClass() != obj.getClass())
        return false;
    Employee other = (Employee) obj;
    if (empId != other.empId)
        return false;
    if (empName == null) {
        if (other.empName != null)
            return false;
    } else if (!empName.equals(other.empName))
        return false;
    return true;
}}

答案 2 :(得分:0)

应该在Bootstrap 4.1中修复。

https://blog.getbootstrap.com/2018/04/09/bootstrap-4-1/

答案 3 :(得分:-1)

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

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