【发布时间】:2017-12-12 08:07:32
【问题描述】:
即使在使用 animation-iteration-count 到 1 和 animation-fill-mode 到 forwards 之后,我也无法使用 css3 动画将动画播放状态设为 paused:
var isRunning = window.getComputedStyle(
document.querySelector('div')
).getPropertyValue('animation-play-state');
setInterval(function(){
console.log(isRunning);
},1000)
@keyframes foo {
0% {
width: 0;
}
100% {
width: 50%;
}
}
div {
animation: foo 2s linear 0s 1 normal forwards;
background-color: #f00;
height: 3px;
}
<div></div>
当它完成动画时,我应该将animation-play-state 变成paused。
实际上,我提供的以下答案对我不起作用。事实上,我正在使用一个伪元素,而伪元素不接受 addEventListener。因此,我的最终解决方案是仅使用这种方式。
var isRunning = window.getComputedStyle(
document.querySelector('div'), ':after'
).getPropertyValue('animation-play-state');
遗憾的是,当动画完成时,CSS 似乎没有将播放状态设置为暂停。总结这个问题没有发现或解决方案?
【问题讨论】:
-
但是我在我的 sn-p 中看不到控制台。任何人都可以修复 sn-p 以显示控制台。谢谢。
-
我无需编辑即可运行它。
-
哦,那它可能没有在 linux chromium 浏览器中显示...
-
没问题。 :-)
-
控制台是作为div实现的,所以会受到动画的影响。解决方案是不使用像 div 这样的通用选择器。给你的 div 一个 id 什么的。
标签: javascript css css-animations