<div>
</div>
This is Framer Motion. Add a "motion." prefix. Sprinkle some props. Animate on!
It's THAT easy!
But, let me ask you a question. 👇
<div>
<motion.span
animate={{ scale: 4 }}>
👊
</motion.span>
</div>
What kind of animation would you get?
The correct answer is D because -- there is no animation at all!
It's NOT a bug. It's due to the rules of HTML:span
has display: inline
by default, and CSS transforms (such asscale
) don't work on inline elements if its parent is a block element. To make it work, we could set its display to either block
or inline-block
. You can play with the code here.
Framer Motion is a great library. But it can be tricky to get it to work in real-world applications. This is not to blame the library. It's because the reality is complex. Web development sometimes IS tricky!
Here are a few more examples:
AnimatePresence
work even if you set the element to display: none
?<AnimateSharedLayout type="crossfade">
behave the same as <AnimateSharedLayout type="switch">
?I've struggled on questions like these since 2019 when Motion V1 was launched. You'd likely, if not already, stumble upon them too!
I've spent hundreds of hours chasing down the why's and solutions. As an example, it took me 3 days to understand AnimateSharedLayout
and its relationship to AnimatePresence
. Three full days!
I'm a full-stack developer and I love design. I've been teaching React since 2017 and I'm loving it! I'm also the author of a couple of courses at Treehouse and Lynda.
My dark little secret: 😈 creating this course is also my special way to learn all things about design and React -- trying to explain things clearly has taken my understanding of the concepts to a whole new level.
Thrilled to be on this journey with you!
I'm a designer and animator. I draw inspiration from my dream diaries.
In my dreams, I saw mammoths chasing little bears on a circus. I managed to turn missiles launched from North Korea into splendid firework shows. I convinced the Emperor of Qin Dynasty to stop killing. I chatted with Prince Edwards in Chinese. I was left in awe by the weirdly breathtaking scenes made up of lily pads, lotus, water grass and pale dead fish...
What's in your dreams?