Jump to content
Search Community

Recommended approach for animating presence of DOM elements

Roman Kopo
Moderator Tag

Go to solution Solved by Rodrigo,

Recommended Posts

Roman Kopo
Posted

Hi,
I'm working with React and think of something like <AnimatePresence/> which is available in (Framer) Motion. The goal is to remove or add an element from the DOM with an animation. What's the recommended way to achieve this? Is there something available like the AnimatePresence component in Framer?

  • Solution
Rodrigo
Posted

Hi @Roman Kopo and welcome to the GSAP Forums!

 

At the moment there isn't something like that, the approach I could suggest is a conditional rendering using the onComplete when removing an element. When adding an element you can use add the element with an opacity: 0 and then apply the other transforms you want/need.

 

Another option could be to borrow some logic from this demo:

See the Pen MWmqzjE by GreenSock (@GreenSock) on CodePen.

 

Hopefully this helps

Happy Tweening!

  • Like 1
Roman Kopo
Posted

thanks @Rodrigo for your suggestion of the preferred implementation and the example!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...