言語
日本語
English

Caution

お使いのブラウザはJavaScriptが無効になっております。
当サイトでは検索などの処理にJavaScriptを使用しています。
より快適にご利用頂くため、JavaScriptを有効にしたうえで当サイトを閲覧することをお勧めいたします。

CSS辞典

  1. トップページ
  2. CSS辞典
  3. 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;}
}

対応ブラウザ

Chrome Chrome
43 以降
42
41
40
39
38
37
36
35
↑ prefix『-webkit-』が必要
2 以前 ×
Firefox Firefox
16 以降
15
14
13
12
11
10
9
8
↑ prefix『-moz-』が必要
4 以前 ×
Safari Safari
9 以降
8
7
6
5
4
↑ prefix『-webkit-』が必要
3 以前 ×
Edge Edge
12 以降
全バージョンで対応しています
IE IE
11
10
9 ×
8 ×
7 ×
6 ×
Opera Opera
30 以降
29
28
27
26
25
24
23
22
↑ prefix『-webkit-』が必要
29
28
27
26
25
24
23
22
↑ prefix『-o-』が必要
11 以前 ×
iOS Safari iOS Safari
9 以降
8
7
6
5
4
↑ prefix『-webkit-』が必要
2 以前 ×
Android Android Browser
43 以降
4.4
↑ prefix『-webkit-』が必要
3 以前 ×
Chrome Android Chrome Android
最新版
デスクトップ版と同等の対応です
Firefox Android Firefox Android
最新版
デスクトップ版と同等の対応です

※ バージョン情報は MDN / Can I Use に基づいています。

概要

アニメーションの繰り返しの回数を指定できます。

『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;}
}

記事の間違いや著作権の侵害等ございましたらお手数ですがまでご連絡頂ければ幸いです。