【问题标题】:Loop animation for csscss的循环动画
【发布时间】:2021-11-12 08:49:06
【问题描述】:

请问我怎样才能让下面的动画在没有 javascript 的情况下继续循环,只有 CSS 和 HTML。因此,当它到达 7 时,它将重新从一个开始,并继续这种方式,直到页面关闭。我已经为此工作了3个多小时。如果有人能指导我,我将不胜感激。

提前谢谢你。

.merry {
  font-family: "Georgia", serif;
  font-style: italic;
  font-size: 18px;
  text-align: center;
}

.merry-text {
  left: 0;
  margin-bottom: 0;
  margin-top: 50px;
  opacity: 0;
  position: absolute;
  right: 0;
  text-align: center;
  top: 0;
}

.merry-text:nth-of-type(1) {
  animation-name: rotate;
  animation-duration: 2.5s;
  animation-delay: 1s;

}

.merry-text:nth-of-type(2) {
  animation-name: rotate;
  animation-duration: 2.5s;
  animation-delay: 3s;

}

.merry-text:nth-of-type(3) {
  animation-name: rotate;
  animation-duration: 2.5s;
  animation-delay: 5s;

}
.merry-text:nth-of-type(4) {
  animation-name: rotate;
  animation-duration: 2.5s;
  animation-delay: 7s;
  animation-fill-mode: forwards;
}
.merry-text:nth-of-type(5) {
  animation-name: rotate;
  animation-duration: 2.5s;
  animation-delay: 9s;
}
.merry-text:nth-of-type(6) {
  animation-name: rotate;
  animation-duration: 2.5s;
  animation-delay: 11s;
}
.merry-text:nth-of-type(7) {
  animation-name: rotate;
  animation-duration: 2.5s;
  animation-delay: 13s;
}
@keyframes rotate {
  0% {
    opacity: 0;
    transform: translate3d(0, 50px, 0);
  }
  
  20%, 80% {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
  
  100% {
    opacity: 0;
    transform: translate3d(0, -25px, 0);
  }
}
<p class="merry">
  <span class="merry-text">circle 1</span>
  <span class="merry-text">circle 2</span>
  <span class="merry-text">circle 3 </span>
    <span class="merry-text">circle 4</span>
    <span class="merry-text">circle 5</span>
    <span class="merry-text">circle 6</span>  
<span class="merry-text">circle 7</span>
</p>

【问题讨论】:

  • animation-iteration-count: infinite; - developer.mozilla.org/en-US/docs/Web/CSS/…
  • 是的,我添加了,但是添加时文本重叠。
  • 那么你的其他动画值很可能需要调整。
  • 不是对单个元素进行动画处理,而是对整个容器进行动画处理,使一次只有一个可见并且您会看到滚动效果,然后将此无限属性添加到该动画中,希望对您有所帮助。
  • 如果可以请您帮忙。

标签: css animation


【解决方案1】:

只需使用这个:

animation-iteration-count: infinite;

【讨论】:

  • 您的答案可以通过额外的支持信息得到改进。请编辑以添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。您可以在帮助中心找到更多关于如何写出好的答案的信息。 ——
猜你喜欢
  • 1970-01-01
  • 2017-04-22
  • 1970-01-01
  • 2013-05-01
  • 2015-05-20
  • 2021-12-28
  • 2021-07-21
  • 2023-03-31
  • 2019-07-06
相关资源
最近更新 更多