CSS淡入/淡出背景图像显示空白的最后一个图像

时间:2018-12-21 21:15:22

标签: html css

我一直试图将仅更改CSS的背景图像应用于div,但是由于某些原因,在指定的三张图像的末尾,出现一段背景,背景只是原始的黑色背景色。更奇怪的是,如果我将转换时间切换为4秒,则其中一张图像根本不会显示。有没有人有办法解决吗?可以在此处找到页面(链接已删除)

CSS:     * {       填充:0;       边距:0     }

body {
  background-color: #000000;
}

.crossfade > figure {
  animation: imageAnimation 30s linear infinite 0s;
  backface-visibility: hidden;
  background-size: cover;
  background-position: center center;
  color: transparent;
  height: 100%;
  left: 0px;
  opacity: 0;
  position: absolute;
  top: 0px;
  width: 100%;
  z-index: 0;
}

.crossfade > figure:nth-child(1) {
  background-image: url('assets/img/landing/gym_1.jpg');
}
.crossfade > figure:nth-child(2) {
  animation-delay: 6s;
  background-image: url('assets/img/landing/gym_2.jpg');
}
.crossfade > figure:nth-child(3) {
  animation-delay: 12s;
  background-image: url('assets/img/landing/weights.jpg');
}

@keyframes imageAnimation {
  0% {
    animation-timing-function: ease-in;
    opacity: 0;
  }
  8% {
    animation-timing-function: ease-out;
    opacity: 1;
  }
  17% {
    opacity: 1
  }
  25% {
    opacity: 0
  }
  100% {
    opacity: 0
  }
}

HTML:

<div class="crossfade">
<figure></figure>
<figure></figure>
<figure></figure>

1 个答案:

答案 0 :(得分:0)

我以为是你的时间。

动画持续30秒钟,并持续75%的时间,图像为opacity: 0,无过渡。这意味着在19.5秒(figure:nth-child(3)的延迟为25%+ 12秒)之后,接下来的10.5秒将看不到任何动画,直到动画重新开始figure:nth-child(1)

将其更改为所有值都是三分之二应该使事情整洁(即66%的时间中有opacity: 0,并将延迟更新为10s或持续时间为18s)。另外,您可以设置4个figures并将延迟更改为7.5的倍数。

相关问题