





animation-play-stateプロパティは、要素にキーフレームアニメーションを適用する場合に、
再生中か一時停止かを指定する際に使用します。
初期値はrunningでアニメーションが再生されますが、値にpausedを指定すると一時停止にすることができます。
一時停止中のアニメーションを再生するには、値をrunningにします。
一時停止中のアニメーションは、一時停止した時点の状態で静止して表示され続けます。
再開されるときには、アニメーションの最初からではなく、その状態から再生されます。
尚、animation-play-stateプロパティは、他の方法で同じ効果を得られるという理由から仕様からの削除が検討されています。
例えば、アニメーションを一度削除してから再指定するなどの方法で、再生と一時停止を切り替えることが可能なためです。
■値
- running
- アニメーションを再生中にする(初期値)
- paused
- アニメーションを一時停止にする
■初期値・適用対象・値の継承
- 初期値
- running
- 適用対象
- すべての要素、:before疑似要素、:after疑似要素
- 値の継承
- しない
■使用例
CSSソースは外部ファイル(sample.css)に記述
div.sample {
animation-name: anime1;
animation-duration: 5s;
animation-timing-function: ease;
animation-iteration-count: infinite;
animation-play-state: paused;
}
@keyframes anime1 {
0% {width: 50px; height: 50px; background-color: aqua;}
100% {width: 200px; height: 50px; background-color: blue;}
}
HTMLソース
<html>
<head>
<link rel=”stylesheet” href=”sample.css” type=”text/css”>
</head>
<body>
<div class=”sample”>animation効果のサンプル</div>
</body>
</html>
ブラウザ上の表示
■ベンダープレフィックスを付けた場合の使用例
CSSソースは外部ファイル(sample.css)に記述
div.prefix_sample {
-moz-animation-name: anime1;
-moz-animation-duration: 5s;
-moz-animation-timing-function: ease;
-moz-animation-iteration-count: infinite;
-moz-animation-play-state: paused;
-webkit-animation-name: anime1;
-webkit-animation-duration: 5s;
-webkit-animation-timing-function: ease;
-webkit-animation-iteration-count: infinite;
-webkit-animation-play-state: paused;
-o-animation-name: anime1;
-o-animation-duration: 5s;
-o-animation-timing-function: ease;
-o-animation-iteration-count: infinite;
-o-animation-play-state: paused;
-ms-animation-name: anime1;
-ms-animation-duration: 5s;
-ms-animation-timing-function: ease;
-ms-animation-iteration-count: infinite;
-ms-animation-play-state: paused;
}
@-moz-keyframes anime1 {
0% {width: 50px; height: 50px; background-color: aqua;}
100% {width: 200px; height: 50px; background-color: blue;}
}
@-webkit-keyframes anime1 {
0% {width: 50px; height: 50px; background-color: aqua;}
100% {width: 200px; height: 50px; background-color: blue;}
}
@-o-keyframes anime1 {
0% {width: 50px; height: 50px; background-color: aqua;}
100% {width: 200px; height: 50px; background-color: blue;}
}
@-ms-keyframes anime1 {
0% {width: 50px; height: 50px; background-color: aqua;}
100% {width: 200px; height: 50px; background-color: blue;}
}
HTMLソース
<html>
<head>
<link rel=”stylesheet” href=”sample.css”
type=”text/css”>
</head>
<body>
<div class=”prefix_sample”>animation効果のサンプル</div>
</body>
</html>
ブラウザ上の表示