【问题标题】:CSS animation delay in between loop循环之间的 CSS 动画延迟
【发布时间】:2015-05-20 14:44:13
【问题描述】:

试图让一个带有 class price 的标签向上滑动,然后用 CSS 向下滑动。

我有以下 --

-webkit-animation-name: slidingPrice;
-webkit-animation-duration: 300ms;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: ease-in-out;
-webkit-animation-delay: 4s;

@-webkit-keyframes slidingPrice {
  0% { opacity: 0; bottom: -30px; }
  50% { opacity: 1; bottom: 0; }
  100% { opacity: 0; bottom: -30px; }
}

我看到动画在 4 秒后开始,但一旦开始,就会以快速的方式连续循环。如何在每个循环之间添加 4 秒延迟并在 50% 标记处停止 2 秒?

【问题讨论】:

标签: css animation delay


【解决方案1】:

延长循环并添加更多关键帧。

@-webkit-keyframes slidingPrice {
  0%     { opacity: 0; bottom: -30px; } /* 0ms initial values */
  2.38%  { opacity: 1; bottom: 0; }     /* 150ms half of animation */
  34.13% { opacity: 1; bottom: 0; }     /* 2150ms still at half of animation */
  36.51% { opacity: 0; bottom: -30px; } /* 2300ms back to initial */
  100%   { opacity: 0; bottom: -30px; } /* 6300ms still at initial */
}

.price {
    -webkit-animation-name: slidingPrice;
    -webkit-animation-duration: 6300ms;
    -webkit-animation-iteration-count: infinite;
    -webkit-animation-timing-function: ease-in-out;
    -webkit-animation-delay: 4s;
}

【讨论】:

  • 以防万一你需要反向动画-webkit-animation-direction: alternate, reverse, normal;
猜你喜欢
  • 2023-04-07
  • 1970-01-01
  • 2016-07-05
  • 2019-05-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多