如何延迟动画滚动背景(CSS)的外观?

时间:2017-12-12 16:11:00

标签: css animation

我有一系列动画,每个都延迟显示为一个接一个。 序列:

  1. 标志
  2. H1
  3. 小时
  4. 后台开始向上滚动
  5. 使用animation-fill-mode: backwards每个元素都不会出现在页面上,直到它被动画化。我希望同样的事情发生在背景中。所以直到所有其他动画都完成才会出现。然后背景将开始向上滚动。

    /*Top Gif*/
    
    .banner {
      position: relative;
      float: left;
      width: 100%;
      height: 400px;
      text-align: center;
    }
    
    .opening {
      display: block;
      background: url(http://subtlepatterns2015.subtlepatterns.netdna-cdn.com/patterns/footer_lodyas.png);
      animation: 100s scroll infinite linear;
      animation-delay: 3s;
      animation-fill-mode: background;
      margin: 2px 0 0 0;
    }
    
    .textBox {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
    }
    
    .logo {
      width: 300px;
      margin-bottom: 20px;
    }
    
    .logo--animated {
      animation: popUp 1s ease-out;
    }
    
    .textBox h1 {
      color: #FFF;
      font-size: 60px;
      text-shadow: 0px 4px 3px rgba(0, 0, 0, 0.4), 0px 8px 13px rgba(0, 0, 0, 0.1), 0px 18px 23px rgba(0, 0, 0, 0.1);
      line-height: 50px;
      animation: moveInRight 0.7s ease-out;
      animation-delay: 1.2s;
      animation-fill-mode: backwards;
    }
    
    hr.style-two {
      border: 0;
      height: 3px;
      background-image: linear-gradient(to right, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.75), rgba(255, 255, 255, 0));
      animation: moveInRight 0.4s ease-out;
      animation-delay: 1.9s;
      animation-fill-mode: backwards;
    }
    
    .textBox h4 {
      line-height: 10px;
      font-weight: normal;
      font-size: 20px;
      animation: moveInRight 0.6s ease-out;
      animation-delay: 2.3s;
      animation-fill-mode: backwards;
    }
    
    
    /*Animations*/
    
    @keyframes scroll {
      100% {
        background-position: 0px -3000px;
      }
    }
    
    @keyframes popUp {
      0% {
        opacity: 0;
        transform: translateY(50px);
      }
      100% {
        opacity: 1;
        transform: translateY(0px);
      }
    }
    
    @keyframes moveInRight {
      0% {
        opacity: 0;
        transform: translateX(-80px);
      }
      100% {
        opacity: 1;
        transform: translate(0);
      }
    }
    <div class="row">
      <div class="col-lg-12">
        <div class="banner opening">
          <div class="opening">
            <div class="textBox">
              <img class="logo logo--animated" src="logo.png">
              <h1>Title</h1>
              <hr class="style-two">
              <h4>Sub-Title</h4>
            </div>
          </div>
        </div>
      </div>
    </div>

1 个答案:

答案 0 :(得分:0)

如果您想要显示背景,请尝试此操作。

/*Top Gif*/

.banner {
  position: relative;
  float: left;
  width: 100%;
  height: 400px;
  text-align: center;
}

.opening {

  animation-delay: 5s;
  display: block;
  animation: 100s scroll infinite linear;
  animation-delay: 3s;
  animation-fill-mode: forwards;
  margin: 2px 0 0 0;
}

.textBox {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.logo {
  width: 300px;
  margin-bottom: 20px;
}

.logo--animated {
  animation: popUp 1s ease-out;
}

.textBox h1 {
  color: #FFF;
  font-size: 60px;
  text-shadow: 0px 4px 3px rgba(0, 0, 0, 0.4), 0px 8px 13px rgba(0, 0, 0, 0.1), 0px 18px 23px rgba(0, 0, 0, 0.1);
  line-height: 50px;
  animation: moveInRight 0.7s ease-out;
  animation-delay: 1.2s;
  animation-fill-mode: backwards;
}

hr.style-two {
  border: 0;
  height: 3px;
  background-image: linear-gradient(to right, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.75), rgba(255, 255, 255, 0));
  animation: moveInRight 0.4s ease-out;
  animation-delay: 1.9s;
  animation-fill-mode: backwards;
}

.textBox h4 {
  line-height: 10px;
  font-weight: normal;
  font-size: 20px;
  animation: moveInRight 0.6s ease-out;
  animation-delay: 2.3s;
  animation-fill-mode: backwards;
}


/*Animations*/

@keyframes scroll {
0% {
  background-image: url(http://subtlepatterns2015.subtlepatterns.netdna-cdn.com/patterns/footer_lodyas.png);
}
  100% {
  background-image: url(http://subtlepatterns2015.subtlepatterns.netdna-cdn.com/patterns/footer_lodyas.png);
    background-position: 0px -3000px;
  }
}

@keyframes popUp {
  0% {
    opacity: 0;
    transform: translateY(50px);
  }
  100% {
    opacity: 1;
    transform: translateY(0px);
  }
}

@keyframes moveInRight {
  0% {
    opacity: 0;
    transform: translateX(-80px);
  }
  100% {
    opacity: 1;
    transform: translate(0);
  }
}
<div class="row">
  <div class="col-lg-12">
    <div class="banner opening">
      <div class="opening">
        <div class="textBox">
          <img class="logo logo--animated" src="logo.png">
          <h1>Title</h1>
          <hr class="style-two">
          <h4>Sub-Title</h4>
        </div>
      </div>
    </div>
  </div>
</div>