gpt4 book ai didi

Css 动画生命周期

转载 作者:行者123 更新时间:2023-11-28 11:39:15 25 4
gpt4 key购买 nike

我不明白如何在一段固定的时间内运行动画。

这是动画的来源:

@-webkit-keyframes pulse {
0% {
-webkit-transform: scale(1);
transform: scale(1);
}

50% {
-webkit-transform: scale(1.1);
transform: scale(1.1);
}

100% {
-webkit-transform: scale(1);
transform: scale(1);
}
}

.pulse {
-webkit-animation-name: pulse;
}

所以我修改了我想要应用 pulse 的元素的 css。

-webkit-animation-duration: 10s;
-webkit-animation-delay: 0s;
-webkit-animation-iteration-count: 10;

据我了解文档,动画应该运行 10 次,每次 10 秒。所以,总共 100 秒。但这是错误的。将动画生命周期指定为 100 秒的正确方法是什么?

最佳答案

好吧,所以你说你得到的计时功能不正确,我不同意,当你将动画持续时间设置为 10s 时,第一个周期为 5s ,并在接下来的 5 秒内让您的 div 横向扩展。

我在这里使用 JavaScript 倒计时,并且还使用设置为 1 秒的 animation-delay 属性,只是为了与我从 here 中获取的 JavaScript 倒计时同步。 ...

因此,如果您看到,动画在 1 处完美结束,因此它可以完美运行,如果您希望做其他事情,请发表评论,我会相应地修改我的答案..

Demo (我已将动画迭代减少到 2 = 20 秒)

Note: Use Chrome to see the Demo as OP is using only -webkit and haven't requested any code for Firefox or Internet Explorer.

@-webkit-keyframes pulse {
0% {
-webkit-transform: scale(1);
transform: scale(1);
}
50% {
-webkit-transform: scale(2);
transform: scale(2);
}
100% {
-webkit-transform: scale(1);
transform: scale(1);
}
}

.pulse {
-webkit-animation-name: pulse;
-webkit-animation-duration: 10s;
-webkit-animation-delay: 1s;
-webkit-animation-iteration-count: 2;
position: absolute;
left: 50%;
font-size: 50px;
top: 10%;
}

关于Css 动画生命周期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21350194/

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