【发布时间】:2015-11-13 00:13:02
【问题描述】:
没有js是否可以再次运行css动画?
@-webkit-keyframes aaa {
to {
background: red;
}
}
input:checked + div {
-webkit-animation-fill-mode: forwards;
-webkit-animation-name: aaa;
-webkit-animation-duration: 1s;
}
div {
width: 100px;
height: 100px;
background:blue;
-webkit-animation-fill-mode: forwards;
-webkit-animation-name: aaa;
-webkit-animation-duration: 1s;
}
选中复选框后,我想再次运行我的动画吗?
<input type="checkbox" />
<div></div>
【问题讨论】:
-
请看我的回答here。你的问题是不同的,但重点是一样的。您不能仅使用 CSS 重新启动动画。
-
@FabrizioCalderan:我认为 OP 希望动画在加载时运行一次,然后在检查输入时再次运行。
-
如果你duplicate the
keyframesblock and give it a different name and use that name in the:checkedrule(在 Chrome 上测试),你可以。根据您的用例,这可能是可取的,也可能不是可取的。然后动画在页面加载时以及复选框的每次更改时运行。