在最后一帧停止 CSS3 动画
我有一个 4 部分的 CSS3 动画,点击时播放 - 但动画的最后一部分是为了将其从屏幕上移开。
然而,一旦播放完毕,它总是会回到原来的状态。任何人都知道我如何在最后一个CSS帧(100%)上停止它,或者如何在播放后删除它所在的整个div。
@keyframes colorchange {
0% { transform: scale(1.0) rotate(0deg); }
50% { transform: rotate(340deg) translate(-300px,0px) }
100% { transform: scale(0.5) rotate(5deg) translate(1140px,-137px); }
}
I have a 4 part CSS3 animation playing on click - but the last part of the animation is meant to take it off the screen.
However, it always goes back to its original state once it has played. Anyone know how I can stop it on its last css frame (100%), or else how to get rid of the whole div it is in once it has played.
@keyframes colorchange {
0% { transform: scale(1.0) rotate(0deg); }
50% { transform: rotate(340deg) translate(-300px,0px) }
100% { transform: scale(0.5) rotate(5deg) translate(1140px,-137px); }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
您正在寻找:
有关 MDN 的更多信息 和 canIuse 上的浏览器支持列表。
You're looking for:
More info on MDN and browser support list on canIuse.
如果您想将此行为添加到速记
animation
属性定义中,子属性的顺序如下animation-name
- default <代码>无动画持续时间
- 默认0s
动画计时功能
- 默认轻松
动画延迟
- 默认0s
动画迭代计数 - 默认
1
动画方向
- 默认正常
动画-fill-mode
- 您需要将其设置为forwards
animation-play-state
- 默认running
因此,在最常见的情况下,结果将是这样的
请参阅MDN 文档位于此处
If you want to add this behaviour to a shorthand
animation
property definition, the order of sub-properties is as followsanimation-name
- defaultnone
animation-duration
- default0s
animation-timing-function
- defaultease
animation-delay
- default0s
animation-iteration-count
- default1
animation-direction
- defaultnormal
animation-fill-mode
- you need to set this toforwards
animation-play-state
- defaultrunning
Therefore in the most common case, the result will be something like this
See the MDN documentation here
浏览器支持
用法:-
Browser Support
Usage:-
最好的方法似乎是将最终状态放在 css 的主要部分。像这里一样,我将宽度设置为
220px
,这样它最终就变成了220px
。但开始0px;
The best way seems to put the final state at the main part of css. Like here, i put width to
220px
, so that it finally becomes220px
. But starting to0px;
您的问题不是将 webkitAnimationName 设置为空,从而将对象的 CSS 重置回默认状态。如果您只是删除重置状态的 setTimeout 函数,它不会停留在最终位置吗?
Isn't your issue that you're setting the webkitAnimationName back to nothing so that's resetting the CSS for your object back to it's default state. Won't it stay where it ended up if you just remove the setTimeout function that's resetting the state?
我刚刚发布了类似的答案,您可能想看看:
http://www.w3.org/TR/css3-animations/#animation-events-
您可以了解动画的各个方面,例如开始和停止,然后说出“停止”事件被解雇了你可以对dom做任何你想做的事。我前一段时间尝试过,它可以工作,但我猜你暂时只能使用 webkit(但你可能已经接受了)。顺便说一句,因为我已经发布了 2 个答案的相同链接,所以我提供一般性建议:查看 W3C - 他们几乎编写了规则并描述了标准。此外,webkit 开发页面也非常关键。
I just posted a similar answer, and you probably want to have a look at:
http://www.w3.org/TR/css3-animations/#animation-events-
You can find out aspects of an animation, such as start and stop, and then, once say the 'stop' event has fired you can do whatever you want to the dom. I tried this out some time ago, and it can work, but I'd guess you're going to be restricted to webkit for the time being (but you've probably accepted that already). Btw, since I've posted the same link for 2 answers, I'd offer this general advice: check out the W3C - they pretty much write the rules and describe the standards. Also, the webkit development pages are pretty key.
实际上没有人这样做,它的工作方式是 animation-play-state 设置为暂停。
Nobody actualy brought it so, the way it was made to work is animation-play-state set to paused.
我今天了解到填充模式有一个限制。这是来自苹果开发者的。传言是 * 左右 * 六,但不确定。
或者,您可以将类的初始状态设置为您希望动画结束的方式,然后在 from / 0% 处初始化它。
I learned today that there is a limit you want to use for the fill-mode. This is from an Apple dev. Rumor is * around * six, but not certain.
Alternatively, you can set the initial state of your class to how you want the animation to end, then * initialize * it at from / 0% .