CSS animation-play-state 属性
CSS animation-play-state 属性定义一个动画是否运行或者暂停。可以通过查询它来确定动画是否正在运行。另外,它的值可以被设置为暂停和恢复的动画的重放。
恢复一个已暂停的动画,将从它开始暂停的时候,而不是从动画序列的起点开始在动画。
实例
暂停动画:
<!DOCTYPE html><html><head><style>div{width:100px;height:100px;background:red;position:relative;animation:mymove 5s;animation-play-state:paused;/* Safari and Chrome */-webkit-animation:mymove 5s;-webkit-animation-play-state:paused;}@keyframes mymove{from {left:0px;}to {left:200px;}}@-webkit-keyframes mymove /* Safari and Chrome */{from {left:0px;}to {left:200px;}}</style></head><body><p><strong>注释:</strong>Internet Explorer 9 以及更早的版本不支持 animation-play-state 属性。</p><div></div></body></html>
浏览器支持
表格中的数字注明了完全支持该属性的首个浏览器版本。
带 -webkit-、-moz- 或 -o- 的数字表示使用前缀的首个版本。
| 属性 | |||||
|---|---|---|---|---|---|
| animation-play-state | 43.04.0 -webkit- | 10.0 | 16.05.0 -moz- | 9.04.0 -webkit- | 30.015.0 -webkit-12.0 -o- |
定义和用法
animation-play-state 属性规定动画正在运行还是暂停。
注释:您可以在 JavaScript 中使用该属性,这样就能在播放过程中暂停动画。
| 默认值: | running |
|---|---|
| 继承性: | no |
| 版本: | CSS3 |
| JavaScript 语法: | object.style.animationPlayState="paused" |
语法
animation-play-state: paused|running;
| 值 | 描述 |
|---|---|
| paused | 规定动画已暂停。 |
| running | 规定动画正在播放。 |
相关页面
CSS3 教程:CSS3 动画