CSS Animation Play State

Language

CSS animation-play-state

In this tutorial we are going to learn about animation-play-state. So, what is animation-play-state? The animation-play-state property specifies whether the animation is paused or running. Syntax of this property: animation-play-state: paused | running | initial | inherit ; Property Values
  • paused - specifies that the animation is paused.
  • running - specifies that the animation is running. The default value is running.
  • initial - specifies that the value of the property should be set to the default value.
  • inherit - specifies that the value of the property should be inherited from the parent element.
Example This example shows the use of the animation-play-state property.

CSS Style

  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. animation:boxmove 5s infinite;
  11. /* Firefox */
  12. -moz-animation:boxmove 5s infinite;
  13. /* Safari and Google Chrome */
  14. -webkit-animation:boxmove 5s infinite;
  15. }
  16.  
  17. #test1 {
  18. animation-play-state:running;
  19. /* Firefox */
  20. -moz-animation-play-state:running;
  21. /* Safari and Google Chrome */
  22. -webkit-animation-play-state:running;
  23. }
  24.  
  25. #test2 {
  26. animation-play-state:paused;
  27. /* Firefox */
  28. -moz-animation-play-state:paused;
  29. /* Safari and Google Chrome */
  30. -webkit-animation-play-state:paused;
  31. }
  32.  
  33. @keyframes boxmove
  34. {
  35. from {left:0px;}
  36. to {left:210px;}
  37. }
  38.  
  39. @-moz-keyframes boxmove /* Firefox */
  40. {
  41. from {left:0px;}
  42. to {left:210px;}
  43. }
  44.  
  45. @-webkit-keyframes boxmove /* Safari and Google Chrome */
  46. {
  47. from {left:0px;}
  48. to {left:210px;}
  49. }
  50.  
  51. </style>

The Complete Source Code

  1. <!DOCTYPE html>
  2.  
  3.  
  4. <style type="text/css">
  5.  
  6. div.animate {
  7. width:50px;
  8. height:50px;
  9. color:white;
  10. padding:2px;
  11. background:blue;
  12. position:relative;
  13. animation:boxmove 5s infinite;
  14. /* Firefox */
  15. -moz-animation:boxmove 5s infinite;
  16. /* Safari and Google Chrome */
  17. -webkit-animation:boxmove 5s infinite;
  18. }
  19.  
  20. #test1 {
  21. animation-play-state:running;
  22. /* Firefox */
  23. -moz-animation-play-state:running;
  24. /* Safari and Google Chrome */
  25. -webkit-animation-play-state:running;
  26. }
  27.  
  28. #test2 {
  29. animation-play-state:paused;
  30. /* Firefox */
  31. -moz-animation-play-state:paused;
  32. /* Safari and Google Chrome */
  33. -webkit-animation-play-state:paused;
  34. }
  35.  
  36. @keyframes boxmove
  37. {
  38. from {left:0px;}
  39. to {left:210px;}
  40. }
  41.  
  42. @-moz-keyframes boxmove /* Firefox */
  43. {
  44. from {left:0px;}
  45. to {left:210px;}
  46. }
  47.  
  48. @-webkit-keyframes boxmove /* Safari and Google Chrome */
  49. {
  50. from {left:0px;}
  51. to {left:210px;}
  52. }
  53.  
  54.  
  55. </head>
  56.  
  57.  
  58. <div id="test1" class="animate">running</div>
  59. <br />
  60. <div id="test2" class="animate">paused</div>
  61.  
  62. </body>
  63.  
  64. </html>
This is the result of the code above: resultHope that this tutorial will help you a lot. If you are interested in programming, we have an example of programs that may help you even just in small ways. If you want more tutorials, you can visit our website, click here. 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