• Register now to get access to thousands of Tutorials, Leaked content, Hot NSFW and much more. Join us as we build and grow the community.

CSS @keyframes Rule

G3tf0ck3d

Follower Engagement Pro
G Rep
0
0
0
Rep
0
G Vouches
0
0
0
Vouches
0
Posts
88
Likes
108
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 2 900 XP
What is a @keyframes in CSS3?
The @keyframes rule is used to create animations. In general, an animation in CSS3 is defined as changing from one CSS style to another.

Structure:
@keyframes name { selector { styles ; } }

Property Values:
name – it’s specifies the name of the animation. (required)
selector – it’s specifies that percentage of the animation duration.(required)
Possible Value:
0 – 100%
from (same as 0%)
to (same as 100%)

styles - it’s specifies one or more CSS style properties.(required)
Example:
In this example you can see on how to use @keyframes rule to animate the position of a box.

CSS Source Code

  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. @keyframes

    boxmove
  24. {
  25. from {

    left

    :

    0px

    ;

    }
  26. to {

    left

    :

    210px

    ;

    }
  27. }

  28. @-moz-keyframes

    boxmove /* Firefox */
  29. {
  30. from {

    left

    :

    0px

    ;

    }
  31. to {

    left

    :

    210px

    ;

    }
  32. }

  33. @-webkit-keyframes

    boxmove /* Safari and Google Chrome */
  34. {
  35. from {

    left

    :

    0px

    ;

    }
  36. to {

    left

    :

    210px

    ;

    }
  37. }

  38. </style>

Full 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. }

  13. #test1 {
  14. animation-name: boxmove;
  15. animation-duration: 5s;
  16. animation-iteration-count: infinite;
  17. /* Firefox */
  18. -moz-animation-name: boxmove;
  19. -moz-animation-duration: 5s;
  20. -moz-animation-iteration-count: infinite;
  21. /* Safari and Google Chrome */
  22. -webkit-animation-name: boxmove;
  23. -webkit-animation-duration: 5s;
  24. -webkit-animation-iteration-count: infinite;
  25. }

  26. @keyframes boxmove
  27. {
  28. from {left: 0px;}
  29. to {left: 210px;}
  30. }

  31. @-moz-keyframes boxmove /* Firefox */
  32. {
  33. from {left: 0px;}
  34. to {left: 210px;}
  35. }

  36. @-webkit-keyframes boxmove /* Safari and Google Chrome */
  37. {
  38. from {left: 0px;}
  39. to {left: 210px;}
  40. }

  41. </

    style

    >

  42. </

    head

    >

  43. <body

    >

  44. <div

    id

    =

    "test1"

    class

    =

    "animate"

    >

    linear</

    div

    >

  45. </

    body

    >

  46. </

    html

    >

This is the result of the code above:

result.png


Hope that this tutorial will help you a lot.

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.
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

452,513

356,536

356,563

Top
Raidforums