Caution
お使いのブラウザはJavaScriptが実行できない状態になっております。
当サイトはWebプログラミングの情報サイトの為、
JavaScriptが実行できない環境では正しいコンテンツが提供出来ません。
JavaScriptが実行可能な状態でご閲覧頂くようお願い申し上げます。
- トップページ
- CSSプロパティ辞典
- animation-iteration-count
animation-iteration-count
アニメーションの繰り返しの回数を指定できます。
ブラウザのバージョンによっては、ベンダープレフィックス『webkit』、『moz』、『ms』等を付けないと動かない場合があるので、使用する際はベンダープレフィックスを付けるようにした方が無難です。またPCのスペックによっては動きがカクついてしまう場合がありますのでご注意下さい。
サンプルコード
div {
animation-iteration-count: 1;
-webkit-animation-iteration-count: 1;
-moz-animation-iteration-count: 1;
-ms-animation-iteration-count: 1;
}
指定可能な値一覧
| 値 | 効果 |
|---|---|
| 数値 | アニメーションを繰り返す回数を指定します。初期値は『1』です。 |
| infinite | アニメーションを無限に繰り返します。 |
ブラウザでの表示結果
div.hoge1 {
background: #f00;
width: 200px;
animation: hogeanime1 3s;
-webkit-animation: hogeanime1 3s;
-moz-animation: hogeanime1 3s;
-ms-animation: hogeanime1 3s;
animation-iteration-count: 3;
-webkit-animation-iteration-count: 3;
-moz-animation-iteration-count: 3;
-ms-animation-iteration-count: 3;
}
div.hoge2 {
background: #f00;
width: 200px;
animation: hogeanime1 3s;
-webkit-animation: hogeanime1 3s;
-moz-animation: hogeanime1 3s;
-ms-animation: hogeanime1 3s;
animation-iteration-count: infinite;
-webkit-animation-iteration-count: infinite;
-moz-animation-iteration-count: infinite;
-ms-animation-iteration-count: infinite;
}
@keyframes hogeanime1 {
0% { width: 200px;}
100% {width: 400px;}
}
@-webkit-keyframes hogeanime1 {
0% { width: 200px;}
100% {width: 400px;}
}
@-moz-keyframes hogeanime1 {
0% { width: 200px;}
100% {width: 400px;}
}
@-ms-keyframes hogeanime1 {
0% { width: 200px;}
100% {width: 400px;}
}
対応ブラウザ
| IE6 | IE7 | IE8 | IE9 | IE10 | IE11 | Safari | Chrome | Firefox | Opera |
|---|---|---|---|---|---|---|---|---|---|
| iPhone Safari | Android2系 標準ブラウザ | Android4系 標準ブラウザ |
|---|---|---|
概要
アニメーションの繰り返しの回数を指定できます。
『animation』プロパティを使用する際は『animation』の記述とは別に『@keyframes』も指定しなくてはなりませんのでご注意下さい。
『@keyframes』の記述方法は『@keyframes』という記述の後に任意の『アニメーション名』書き、その後に『{}』で囲い、その中で進行状態に合わせたプロパティの変化を『0%』から『100%』の間で記述します。進行状態は『0%』が開始時、『100%』が終了時です。『0%』は『from』、『100%』は『to』という単語で記述することもできますが、『%』で指定するのが一般的です。
/* 以下のように『{}』で囲い、その中で変化のタイミングと状態を指定します。 */
@keyframes hogeanime1 {
0% { width: 200px;}
50% { width: 300px;}
100% { width: 400px;}
}
@-webkit-keyframes hogeanime1 {
0% { width: 200px;}
50% { width: 300px;}
100% { width: 400px;}
}
@-moz-keyframes hogeanime1 {
0% { width: 200px;}
50% { width: 300px;}
100% { width: 400px;}
}
@-ms-keyframes hogeanime1 {
0% { width: 200px;}
50% { width: 300px;}
100% { width: 400px;}
}
『animation-iteration-count』の値は『,』で区切る事により複数のアニメーションの繰り返しの回数を同時に指定できます。
div {
background: #f00;
width: 200px;
animation-name: hogeanime1, hogeanime2;
-webkit-animation-name: hogeanime1, hogeanime2;
-moz-animation-name: hogeanime1, hogeanime2;
-ms-animation-name: hogeanime1, hogeanime2;
animation-duration: 3s, 2s;
-webkit-animation-duration: 3s, 2s;
-moz-animation-duration: 3s, 2s;
-ms-animation-duration: 3s, 2s;
animation-iteration-count: 3, infinite;
-webkit-animation-iteration-count: 3, infinite;
-moz-animation-iteration-count: 3, infinite;
-ms-animation-iteration-count: 3, infinite;
}
@keyframes hogeanime1 {
0% { width: 200px;}
100% {width: 400px;}
}
@-webkit-keyframes hogeanime1 {
0% { width: 200px;}
100% {width: 400px;}
}
@-moz-keyframes hogeanime1 {
0% { width: 200px;}
100% {width: 400px;}
}
@-ms-keyframes hogeanime1 {
0% { width: 200px;}
100% {width: 400px;}
}
@keyframes hogeanime2 {
0% { background: #f00;}
100% {background: #ff0;}
}
@-webkit-keyframes hogeanime2 {
0% { background: #f00;}
100% {background: #ff0;}
}
@-moz-keyframes hogeanime2 {
0% { background: #f00;}
100% {background: #ff0;}
}
@-ms-keyframes hogeanime2 {
0% { background: #f00;}
100% {background: #ff0;}
}
指定されているアニメーション名の数より『animation-iteration-count』の値が少ない場合は指定した値が繰り返されているものとして適用されます。
div {
background: #f00;
width: 200px;
animation-name: hogeanime1, hogeanime2, hogeanime3;
-webkit-animation-name: hogeanime1, hogeanime2, hogeanime3;
-moz-animation-name: hogeanime1, hogeanime2, hogeanime3;
-ms-animation-name: hogeanime1, hogeanime2, hogeanime3;
animation-duration: 3s, 2s;
-webkit-animation-duration: 3s, 2s;
-moz-animation-duration: 3s, 2s;
-ms-animation-duration: 3s, 2s;
animation-iteration-count: 3, infinite;
-webkit-animation-iteration-count: 3, infinite;
-moz-animation-iteration-count: 3, infinite;
-ms-animation-iteration-count: 3, infinite;
}
@keyframes hogeanime1 {
0% { width: 200px;}
100% {width: 400px;}
}
@-webkit-keyframes hogeanime1 {
0% { width: 200px;}
100% {width: 400px;}
}
@-moz-keyframes hogeanime1 {
0% { width: 200px;}
100% {width: 400px;}
}
@-ms-keyframes hogeanime1 {
0% { width: 200px;}
100% {width: 400px;}
}
@keyframes hogeanime2 {
0% { background: #f00;}
100% {background: #ff0;}
}
@-webkit-keyframes hogeanime2 {
0% { background: #f00;}
100% {background: #ff0;}
}
@-moz-keyframes hogeanime2 {
0% { background: #f00;}
100% {background: #ff0;}
}
@-ms-keyframes hogeanime2 {
0% { background: #f00;}
100% {background: #ff0;}
}
@keyframes hogeanime3 {
0% { height: 100px;}
100% {height: 150px;}
}
@-webkit-keyframes hogeanime3 {
0% { height: 100px;}
100% {height: 150px;}
}
@-moz-keyframes hogeanime3 {
0% { height: 100px;}
100% {height: 150px;}
}
@-ms-keyframes hogeanime3 {
0% { height: 100px;}
100% {height: 150px;}
}
指定した『animation-iteration-count』の値がアニメーション名より多い場合は、アニメーション名の数以上の値は無視されます。
div {
background: #f00;
width: 200px;
animation-name: hogeanime1, hogeanime2;
-webkit-animation-name: hogeanime1, hogeanime2;
-moz-animation-name: hogeanime1, hogeanime2;
-ms-animation-name: hogeanime1, hogeanime2;
animation-duration: 3s, 2s;
-webkit-animation-duration: 3s, 2s;
-moz-animation-duration: 3s, 2s;
-ms-animation-duration: 3s, 2s;
animation-iteration-count: 3, infinite, 2;
-webkit-animation-iteration-count: 3, infinite, 2;
-moz-animation-iteration-count: 3, infinite, 2;
-ms-animation-iteration-count: 3, infinite, 2;
}
@keyframes hogeanime1 {
0% { width: 200px;}
100% {width: 400px;}
}
@-webkit-keyframes hogeanime1 {
0% { width: 200px;}
100% {width: 400px;}
}
@-moz-keyframes hogeanime1 {
0% { width: 200px;}
100% {width: 400px;}
}
@-ms-keyframes hogeanime1 {
0% { width: 200px;}
100% {width: 400px;}
}
@keyframes hogeanime2 {
0% { background: #f00;}
100% {background: #ff0;}
}
@-webkit-keyframes hogeanime2 {
0% { background: #f00;}
100% {background: #ff0;}
}
@-moz-keyframes hogeanime2 {
0% { background: #f00;}
100% {background: #ff0;}
}
@-ms-keyframes hogeanime2 {
0% { background: #f00;}
100% {background: #ff0;}
}
記事の間違いや著作権の侵害等ございましたらお手数ですがこちらまでご連絡頂ければ幸いです。