Animation Iteration Count in CSS

Submitted by: 
Language: 
Visitors have accessed this post 634 times.

In this article, we are going tackled about Animation Iteration Count in CSS. What is animation-iteration-count?

Let's discuss a animation-iteration-count.

The animation-iteration-count property specifies how many times an animation should be played.

Syntax of this property:

animation-iteration-count: number | infinite | initial | inherit ;

Property Values

number - it specifies a number that defines how many times an animation should be played. (default = 1)

infinite - it specifies that the animation should be played infinite times.

initial - it specifies that the value of the property should be set to the default value.

inherit - it specifies that the value of the property should be inherited from the parent element.

Example

This example shows how many times an animation should be played.

Copy and paste this source code to your HEAD tag of your page.

  1. <style type="text/css">
  2.  
  3. div.animate {
  4. width:50px;
  5. height:50px;
  6. color:white;
  7. padding:2px;
  8. background:blue;
  9. position:relative;
  10. }
  11.  
  12. #test1 {
  13. animation-name:boxmove;
  14. animation-duration:5s;
  15. animation-iteration-count:infinite;
  16. /* Firefox */
  17. -moz-animation-name:boxmove;
  18. -moz-animation-duration:5s;
  19. -moz-animation-iteration-count:infinite;
  20. /* Safari and Google Chrome */
  21. -webkit-animation-name:boxmove;
  22. -webkit-animation-duration:5s;
  23. -webkit-animation-iteration-count:infinite;
  24. }
  25.  
  26. #test2 {
  27. animation-name:boxmove;
  28. animation-duration:5s;
  29. animation-iteration-count:5;
  30. /* Firefox */
  31. -moz-animation-name:boxmove;
  32. -moz-animation-duration:5s;
  33. -moz-animation-iteration-count:5;
  34. /* Safari and Google Chrome */
  35. -webkit-animation-name:boxmove;
  36. -webkit-animation-duration:5s;
  37. -webkit-animation-iteration-count:5;
  38. }
  39.  
  40. #test3 {
  41. animation-name:boxmove;
  42. animation-duration:5s;
  43. animation-iteration-count:3;
  44. /* Firefox */
  45. -moz-animation-name:boxmove;
  46. -moz-animation-duration:5s;
  47. -moz-animation-iteration-count:3;
  48. /* Safari and Google Chrome */
  49. -webkit-animation-name:boxmove;
  50. -webkit-animation-duration:5s;
  51. -webkit-animation-iteration-count:3;
  52. }
  53.  
  54. @keyframes boxmove
  55. {
  56. from {left:0px;}
  57. to {left:210px;}
  58. }
  59.  
  60. @-moz-keyframes boxmove /* Firefox */
  61. {
  62. from {left:0px;}
  63. to {left:210px;}
  64. }
  65.  
  66. @-webkit-keyframes boxmove /* Safari and Google Chrome */
  67. {
  68. from {left:0px;}
  69. to {left:210px;}
  70. }
  71.  
  72. </style>

Copy and paste this source code to your BODY tag of your page.

  1. <div id="test1" class="animate">infinite</div>
  2. <br />
  3. <div id="test2" class="animate">5 times</div>
  4. <br />
  5. <div id="test3" class="animate">3 times</div>

This is the result of the code above:

result

Kindly click the "Download Code" button below for full source code. Thank you very much.

So what can you say about this work? Share your thoughts in the comment section below or email me at [email protected]. Practice Coding. Thank you very much.


Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3>
  • You may insert videos with [video:URL]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.