animationプロパティは、要素にキーフレームアニメーションを適用する場合に、
アニメーションについてまとめて指定する際に使用します。
animationプロパティでは、
animation-name、
animation-duration、
animation-timing-function、
animation-delay、
animation-iteration-count、
animation-direction の6つのプロパティの値を、組み合わせて指定することができます。
省略された値はそれらの初期の値に設定されます。
■値
- 各プロパティの値をスペースで区切って指定
-
animation-nameの値、
animation-durationの値、
animation-timing-functionの値、
animation-delayの値、
animation-iteration-countの値、
animation-directionの値をスペースで区切って指定する
■初期値・適用対象・値の継承
- 初期値
-
animation-nameはnone、
animation-durationは0、
animation-timing-functionはease、
animation-delayは0、
animation-iteration-countは1、
animation-directionはnormal - 適用対象
- すべての要素、:before疑似要素、:after疑似要素
- 値の継承
- しない
■使用例
CSSソースは外部ファイル(sample.css)に記述
div.sample {
animation: anime1 5s ease -2s infinite alternate;
}
@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: anime1 5s ease -2s infinite alternate;
-webkit-animation: anime1 5s ease -2s infinite alternate;
-o-animation: anime1 5s ease -2s infinite alternate;
-ms-animation: anime1 5s ease -2s infinite alternate;
}
@-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>
ブラウザ上の表示