gpt4 book ai didi

css - 每 3 秒重播一次动画 CSS3

转载 作者:太空宇宙 更新时间:2023-11-04 03:43:08 24 4
gpt4 key购买 nike

我制作了一个 css3 动画,但需要每 3 秒无限运行一次,仅使用 css 无法做到。

CSS3

.halo-robford-animate{
animation: leaves 0.3s ease-in-out 3 alternate;
-webkit-animation: leaves 0.3s ease-in-out 3 alternate;
}

Codepen

最佳答案

您缺少 animation-iteration-count动画的正式语法是:

animation: <single-animation-name> || <time> || <timing-function> || <time> || <single-animation-iteration-count> || <single-animation-direction> || <single-animation-fill-mode>

Source + additional info

您可以将其更改为:

.halo-robford-animate{
animation: leaves 0.3s ease-in-out 3s infinite alternate;
-webkit-animation: leaves 0.3s ease-in-out 3s infinite alternate;
-moz-animation: leaves 0.3s ease-in-out 3s infinite alternate;
-o-animation: leaves 0.3s ease-in-out 3s infinite alternate;
}

注意 3 的测量需要一个单位,因此添加了一个 s 使其成为 3s。第二次测量是 animation-delay,它指定了开始的延迟,而不是动画之间的延迟。

Demo

或者单独使用属性:

animation-iteration-count: infinite;
-webkit-animation-iteration-count: infinite;
-moz-animation-iteration-count: infinite;
-o-animation-iteration-count: infinite;

如果您希望动画之间有 3 秒的间隔,而动画需要 0.3 秒,则需要稍作调整。将 animation-duration 更改为 3s(这是您拥有的 0.3s)

.halo-robford-animate{
animation: leaves 3s ease-in-out 3s infinite alternate;
-webkit-animation: leaves 3s ease-in-out 3s infinite alternate;
-moz-animation: leaves 3s ease-in-out 3s infinite alternate;
-o-animation: leaves 3s ease-in-out 3s infinite alternate;
}

让动画只在前 0.3 秒发生:

@-webkit-keyframes leaves {
0% {
opacity: 1;
}

5% {
opacity: 0.5;
}

10% {
opacity: 1;
}
}

Demo 2

关于css - 每 3 秒重播一次动画 CSS3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24582162/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com