Reputation: 2610
I am wondering how to do the following scenario with Framer motion: I have a list that appears when I click on a button. The list comes in with a fade-in animation. However, the box of content below will immediately move down without an animation. What I would like to achieve is that the 'box with content' moves downwards smoothly to its new place while the list animation is going on. How can I achieve this? I have made a code sandbox to replicate the situation:
https://codesandbox.io/s/stupefied-shockley-pwxg9e?file=/src/App.js
Upvotes: 1
Views: 8078
Reputation: 1276
Couple of things:
height
from 0
to auto
key
to the items. In your case I used index
I updated your sandbox to work. 1 fixes the content reflow. 2 fixes the exit animation not working
https://codesandbox.io/s/broken-http-n8i2hk?file=/src/App.js
I did a writeup on this feature in Framer Motion, because I think it is rather undocumented. Check it out if you like: https://www.joshuawootonn.com/how-to-animate-width-and-height-with-framer-motion
Upvotes: 1