【发布时间】:2022-01-08 16:40:40
【问题描述】:
我想使用@keyframes,所以我这样做了:
div {
width: 100px;
height: 100px;
background: red;
position: relative;
animation: action 5s infinite;
}
@keyframes action {
0% {top: 0px;}
25% {top: 200px;}
75% {top: 50px}
100% {top: 100px;}
}
但是,此代码会在页面加载时运行。有没有办法用js在某个时间触发@keyframes?例如。
for (var i = 0; i < 10; i++) {
//Do something
}
//Activate @keyframes
谢谢!
【问题讨论】:
-
使用
animation-delay属性。 -
你可以试试
animation-play-state可能吗?您可以在 CSS 中将其设置为暂停并在您的 JS 代码中切换它? -
@PrimeBeat 你会怎么做?
-
@mm4096 我把它作为答案发布在下面
标签: javascript html css css-animations