Fireship · @fireship

CSS Animation in 100 Seconds

Uploaded April 21, 2020 · Length 2:05

CSS Animation in 100 Seconds

Summary

learn how to create css animations with transitions and keyframes in 100 seconds

  • css animation
  • css transitions
  • keyframes animation
  • css easing
  • css animation tutorial

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    animation it's the change from one CSS

  2. 0:02

    style to another over the dimension of

  3. 0:04

    time every animation has at least two

  4. 0:05

    states a starting point and an ending

  5. 0:07

    point when you move from start to finish

  6. 0:09

    CSS will calculate all the values in

  7. 0:12

    between in computer science this is

  8. 0:14

    called inbetweening or a tween animation

  9. 0:16

    imagine we have an element that we want

  10. 0:18

    to fade in over a duration of one second

  11. 0:20

    when the animation starts the browser

  12. 0:22

    calculates a new a pasty value for every

  13. 0:24

    frame rendered and it does so using a

  14. 0:26

    linear timing function which means the

  15. 0:28

    amount of change that occurs to the CSS

  16. 0:30

    value is exactly the same for each unit

  17. 0:32

    of time but in the real physical world

  18. 0:34

    things rarely move at a perfect linear

  19. 0:36

    pace things ease in ease out and change

  20. 0:38

    the velocity gracefully you can do the

  21. 0:40

    same in your CSS animations by providing

  22. 0:42

    a timing function there are many

  23. 0:44

    built-in functions where you can define

  24. 0:46

    your own custom veggie acres the easiest

  25. 0:48

    way to create an animation with CSS is

  26. 0:50

    with a transition start by adding the

  27. 0:52

    transition property to a selector the

  28. 0:54

    first value is the property that you

  29. 0:55

    want to animate in our case its opacity

  30. 0:57

    the second value is the duration you can

  31. 0:59

    define it in seconds or milliseconds now

  32. 1:02

    whenever the opacity for this element

  33. 1:03

    changes CSS will automatically handle

  34. 1:05

    the animation for you for example we can

  35. 1:08

    target the hover pseudo selector and

  36. 1:09

    change the opacity to one and that's all

  37. 1:11

    it takes to create a fade-in fade-out

  38. 1:13

    animation with CSS we can refine this

  39. 1:15

    animation by adding an additional value

  40. 1:17

    for a delay or a timing function use a

  41. 1:20

    built-in easing function or create your

  42. 1:21

    own custom as the a curve but what if

  43. 1:24

    you want to animate something forever or

  44. 1:25

    in multiple steps keyframes allow you to

  45. 1:28

    define animations independent of a

  46. 1:29

    selector first give your keyframe

  47. 1:31

    animation a name then define your

  48. 1:32

    starting styles with from and your

  49. 1:34

    ending styles with to any intermediate

  50. 1:36

    styles or steps in the animation can be

  51. 1:38

    defined as a percentage in relative time

  52. 1:40

    to the starting point if your animation

  53. 1:42

    is 4 seconds long then 25% would be 1

  54. 1:44

    second into that animation you can use

  55. 1:46

    this animation by referencing it as the

  56. 1:48

    animation name in one of your selectors

  57. 1:50

    give it a duration and timing function

  58. 1:52

    then change the iteration count to

  59. 1:53

    infinite to make it loop forever this

  60. 1:55

    has been CSS animation in 100 seconds

  61. 1:57

    hit the like button if you want to see

  62. 1:59

    more short videos like this thanks for