CSS3 动画填充模式 属性

CSS3 Animation-fill-mode property

我正在创建一种效果,其中文本滑入 window 并在动画结束后停留在那里。我已经能够让动画在 1 段文本上运行,但由于某种原因,第二段无法运行。

请看我的fiddlehttps://jsfiddle.net/9fpryou8/

提前致谢。

figure h2.world {
  position: absolute;
  top: 20%;
  left: 61%;
  background-color: transparent;
  font-size: 7em;
  color: white;
  font-family: Paytone One, Verdana, sans-serif;
  transform: translateX(300%);
  text-shadow: 0px 0px 50px black;

  -moz-animation-name: slideWorld;
  -moz-animation-iteration-count: 1;
  -moz-animation-timing-function: ease-in;
  -moz-animation-duration: 0.4s;
  -moz-animation-delay: 1.4s;
  -moz-animation-fill-mode: forwards;

  -webkit-animation-name: slideWorld;
  -webkit-animation-iteration-count: 1;
  -webkit-animation-timing-function: ease-in;
  -webkit-animation-duration: 0.4s;
  -webkit-animation-delay: 1.4s;
  -webkit-animation-fill-mode: forwards;

  animation-name: slideWorld;
  animation-iteration-count: 1.4;
  animation-timing-function: ease-in;
  animation-duration: 0.4s;
  animation-delay: 1.4s;
  animation-fill-mode: forwards;
}

.world中替换

animation-iteration-count: 1.4;

animation-iteration-count: 1;

figure {
    height: 98vh;
    background-color: grey;
}
figure h2.hello {
  position: absolute;
  top: 20%;
  left: 39%;
  font-size: 1em;
  background-color: transparent;
  color: white;
  font-family: Paytone One, Verdana, sans-serif;
  transform: translateX(-400%);
  text-shadow: 0px 0px 50px black;
  
  -moz-animation-name: slideHello;
  -moz-animation-iteration-count: 1;
  -moz-animation-timing-function: ease-in;
  -moz-animation-duration: 0.4s;
  -moz-animation-delay: 1s;
  -moz-animation-fill-mode: forwards;

  -webkit-animation-name: slideHello;
  -webkit-animation-iteration-count: 1;
  -webkit-animation-timing-function: ease-in;
  -webkit-animation-duration: 0.4s;
  -webkit-animation-delay: 1s;
  -webkit-animation-fill-mode: forwards;

  animation-name: slideHello;
  animation-iteration-count: 1;
  animation-timing-function: ease-in;
  animation-duration: 0.4s;
  animation-delay: 1s;
  animation-fill-mode: forwards;
}

figure h2.world {
  position: absolute;
  top: 20%;
  left: 61%;
  background-color: transparent;
  font-size: 1em;
  color: white;
  font-family: Paytone One, Verdana, sans-serif;
  transform: translateX(300%);
  text-shadow: 0px 0px 50px black;
  
  -moz-animation-name: slideWorld;
  -moz-animation-iteration-count: 1;
  -moz-animation-timing-function: ease-in;
  -moz-animation-duration: 0.4s;
  -moz-animation-delay: 1.4s;
  -moz-animation-fill-mode: forwards;

  -webkit-animation-name: slideWorld;
  -webkit-animation-iteration-count: 1;
  -webkit-animation-timing-function: ease-in;
  -webkit-animation-duration: 0.4s;
  -webkit-animation-delay: 1.4s;
  -webkit-animation-fill-mode: forwards;

  animation-name: slideWorld;
  animation-iteration-count: 1;
  animation-timing-function: ease-in;
  animation-duration: 0.4s;
  animation-delay: 1.4s;
  animation-fill-mode: forwards;
}

/**** Display Hello on Load ****/
@-moz-keyframes slideHello {
  to {
    -moz-transform: translateX(-39%);
  }
}
@-webkit-keyframes slideHello {
  to {
    -webkit-transform: translateX(-39%);
  }
}
@keyframes slideHello {
  to {
   transform: translateX(-39%);
  }
}

/**** Display World on Load ****/
@-moz-keyframes slideWorld {
  to {
    -moz-transform: translateX(-61%);
  }
}
@-webkit-keyframes slideWorld {
  to {
    -webkit-transform: translateX(-61%);
  }
}
@keyframes slideWorld {
  to {
   transform: translateX(-61%);
  }
}
<figure>
  <h2 class="hello">Hello</h2>
  <h2 class="world">World</h2>
</figure

或者简单删除:animation-iteration-count的初始值为1

您打字有误

animation-iteration-count: 1.4;更改为animation-iteration-count: 1;

那么它应该可以工作