Fireship · @fireship

Springy Animated Modals // Framer Motion & React Tutorial for Beginners

Uploaded September 14, 2021 · Length 11:03

Springy Animated Modals // Framer Motion & React Tutorial for Beginners

Summary

Learn how to build a modal window with animations using Framer Motion and React from scratch in this beginner-friendly tutorial.

  • framer motion tutorial
  • react animations
  • modal window example
  • beginner react tutorial
  • ui component development

Transcript preview

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

  1. 0:00

    animation is one of the most satisfying

  2. 0:01

    things for a developer because it can

  3. 0:03

    turn a boring cookie cutter feature into

  4. 0:05

    something really special in today's

  5. 0:07

    video we'll build a modal window and

  6. 0:08

    react from scratch but on top of that

  7. 0:11

    we'll also bring in a library called

  8. 0:12

    framer motion to implement a bunch of

  9. 0:14

    crazy animations for the modal in this

  10. 0:16

    beginner-friendly tutorial you'll learn

  11. 0:18

    how to style a modal with css then how

  12. 0:20

    to manage its open and closed state with

  13. 0:22

    javascript and most importantly how to

  14. 0:24

    implement declarative animations with

  15. 0:26

    framer motion and react and i'll even

  16. 0:28

    show you how to drag and move a modal

  17. 0:30

    around the screen and explain the

  18. 0:31

    physics behind motion like this and

  19. 0:33

    we'll look at a bunch of other cool

  20. 0:34

    tricks and best practices along the way

  21. 0:36

    if you're new here like and subscribe

  22. 0:38

    and if you like this tutorial upgrade to

  23. 0:40

    a pro membership on fireship io to get

  24. 0:42

    access to the sequel where we build a

  25. 0:44

    notification system with framer before

  26. 0:46

    we jump into the code let's take a

  27. 0:47

    closer look at what we're building today

  28. 0:49

    and by the way there's also a live demo

  29. 0:50

    where you can play around with this

  30. 0:52

    project before you build it we have a

  31. 0:53

    button that when clicked will add a

  32. 0:55

    backdrop to the entire screen and then

  33. 0:57

    animate a window on top of it then to

  34. 0:59

    close it we can either click the close

  35. 1:01

    button or click outside of it on the

  36. 1:03

    backdrop which will automatically

  37. 1:04

    trigger the outro animation modals are a

  38. 1:07

    very useful ui feature when you need to

  39. 1:09

    focus the user's attention and or you

  40. 1:11

    don't want to navigate them to an

  41. 1:12

    entirely different route you can also do

  42. 1:14

    complex things inside of them for

  43. 1:16

    example the entire login feature for

  44. 1:18

    fireship io is handled inside of a modal

  45. 1:20

    what you don't want to do is pop one of

  46. 1:22

    these things up after a few seconds

  47. 1:23

    asking someone to subscribe to your

  48. 1:25

    newsletter or even worse asking them to

  49. 1:27

    accept cookies let's go ahead and jump

  50. 1:29

    into the code to get started we'll first

  51. 1:31

    need to generate a react project and for

  52. 1:33

    that i'm using create react app once

  53. 1:35

    created i'll go ahead and open it up in

  54. 1:37

    vs code and install our only dependency

  55. 1:39

    which is framer motion framer by the way

  56. 1:42

    is maintained by the team behind the

  57. 1:43

    framer design tool and is a very well

  58. 1:45

    maintained and polished library for

  59. 1:47

    implementing animations it's not the

  60. 1:49

    only way to animate and react but in my

  61. 1:50

    opinion it's the most intuitive approach

  62. 1:52

    for a feature like this now to run the

  63. 1:54

    app run npm start from the command line

  64. 1:56

    and that should bring up the default

  65. 1:58

    react app on localhost 3000. next we'll