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

CSS Animation Play State

raazer

Guild Coordinator
R Rep
0
0
0
Rep
0
R Vouches
0
0
0
Vouches
0
Posts
127
Likes
29
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 200 XP
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. div.animate

    {
  3. width

    :

    50px

    ;
  4. height

    :

    50px

    ;
  5. color

    :

    white

    ;
  6. padding

    :

    2px

    ;
  7. background

    :

    blue

    ;
  8. position

    :

    relative

    ;
  9. animation

    :

    boxmove 5s

    infinite

    ;
  10. /* Firefox */
  11. -moz-animation:

    boxmove 5s

    infinite

    ;
  12. /* Safari and Google Chrome */
  13. -webkit-animation:

    boxmove 5s

    infinite

    ;
  14. }

  15. #test1

    {
  16. animation-play-state

    :

    running;
  17. /* Firefox */
  18. -moz-animation-play-state:

    running;
  19. /* Safari and Google Chrome */
  20. -webkit-animation-play-state:

    running;
  21. }

  22. #test2

    {
  23. animation-play-state

    :

    paused;
  24. /* Firefox */
  25. -moz-animation-play-state:

    paused;
  26. /* Safari and Google Chrome */
  27. -webkit-animation-play-state:

    paused;
  28. }

  29. @keyframes

    boxmove
  30. {
  31. from {

    left

    :

    0px

    ;

    }
  32. to {

    left

    :

    210px

    ;

    }
  33. }

  34. @-moz-keyframes

    boxmove /* Firefox */
  35. {
  36. from {

    left

    :

    0px

    ;

    }
  37. to {

    left

    :

    210px

    ;

    }
  38. }

  39. @-webkit-keyframes

    boxmove /* Safari and Google Chrome */
  40. {
  41. from {

    left

    :

    0px

    ;

    }
  42. to {

    left

    :

    210px

    ;

    }
  43. }

  44. </style>

The Complete Source Code

  1. <!DOCTYPE html>

  2. <html

    >
  3. <head

    >

  4. <style

    type

    =

    "text/css"

    >

  5. div.animate {
  6. width:50px;
  7. height:50px;
  8. color:white;
  9. padding:2px;
  10. background:blue;
  11. position:relative;
  12. animation:boxmove 5s infinite;
  13. /* Firefox */
  14. -moz-animation:boxmove 5s infinite;
  15. /* Safari and Google Chrome */
  16. -webkit-animation:boxmove 5s infinite;
  17. }

  18. #test1 {
  19. animation-play-state:running;
  20. /* Firefox */
  21. -moz-animation-play-state:running;
  22. /* Safari and Google Chrome */
  23. -webkit-animation-play-state:running;
  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. @keyframes boxmove
  33. {
  34. from {left:0px;}
  35. to {left:210px;}
  36. }

  37. @-moz-keyframes boxmove /* Firefox */
  38. {
  39. from {left:0px;}
  40. to {left:210px;}
  41. }

  42. @-webkit-keyframes boxmove /* Safari and Google Chrome */
  43. {
  44. from {left:0px;}
  45. to {left:210px;}
  46. }

  47. </

    style

    >

  48. </

    head

    >

  49. <body

    >

  50. <div

    id

    =

    "test1"

    class

    =

    "animate"

    >

    running</

    div

    >
  51. <br

    /

    >
  52. <div

    id

    =

    "test2"

    class

    =

    "animate"

    >

    paused</

    div

    >

  53. </

    body

    >

  54. </

    html

    >

This is the result of the code above:
result.jpg

Hope 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.


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

452,496

338,631

338,639

Top