• We just launched and are currently in beta. Join us as we build and grow the community.

Animation Iteration Count in CSS

Kumu

Crafting Wizard
K Rep
0
0
0
Rep
0
K Vouches
0
0
0
Vouches
0
Posts
149
Likes
32
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
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. div.animate

    {
  3. width

    :

    50px

    ;
  4. height

    :

    50px

    ;
  5. color

    :

    white

    ;
  6. padding

    :

    2px

    ;
  7. background

    :

    blue

    ;
  8. position

    :

    relative

    ;
  9. }

  10. #test1

    {
  11. animation-name

    :

    boxmove;
  12. animation-duration

    :

    5s

    ;
  13. animation-iteration-count

    :

    infinite

    ;
  14. /* Firefox */
  15. -moz-animation-name:

    boxmove;
  16. -moz-animation-duration:

    5s

    ;
  17. -moz-animation-iteration-count:

    infinite

    ;
  18. /* Safari and Google Chrome */
  19. -webkit-animation-name:

    boxmove;
  20. -webkit-animation-duration:

    5s

    ;
  21. -webkit-animation-iteration-count:

    infinite

    ;
  22. }

  23. #test2

    {
  24. animation-name

    :

    boxmove;
  25. animation-duration

    :

    5s

    ;
  26. animation-iteration-count

    :

    5

    ;
  27. /* Firefox */
  28. -moz-animation-name:

    boxmove;
  29. -moz-animation-duration:

    5s

    ;
  30. -moz-animation-iteration-count:

    5

    ;
  31. /* Safari and Google Chrome */
  32. -webkit-animation-name:

    boxmove;
  33. -webkit-animation-duration:

    5s

    ;
  34. -webkit-animation-iteration-count:

    5

    ;
  35. }

  36. #test3

    {
  37. animation-name

    :

    boxmove;
  38. animation-duration

    :

    5s

    ;
  39. animation-iteration-count

    :

    3

    ;
  40. /* Firefox */
  41. -moz-animation-name:

    boxmove;
  42. -moz-animation-duration:

    5s

    ;
  43. -moz-animation-iteration-count:

    3

    ;
  44. /* Safari and Google Chrome */
  45. -webkit-animation-name:

    boxmove;
  46. -webkit-animation-duration:

    5s

    ;
  47. -webkit-animation-iteration-count:

    3

    ;
  48. }

  49. @keyframes

    boxmove
  50. {
  51. from {

    left

    :

    0px

    ;

    }
  52. to {

    left

    :

    210px

    ;

    }
  53. }

  54. @-moz-keyframes

    boxmove /* Firefox */
  55. {
  56. from {

    left

    :

    0px

    ;

    }
  57. to {

    left

    :

    210px

    ;

    }
  58. }

  59. @-webkit-keyframes

    boxmove /* Safari and Google Chrome */
  60. {
  61. from {

    left

    :

    0px

    ;

    }
  62. to {

    left

    :

    210px

    ;

    }
  63. }

  64. </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_5.png


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.


Download
You must upgrade your account or reply in the thread to view hidden text.
 

442,401

317,942

317,951

Top