Jump to content
Search Community

React GSAP Hover/Out multiple animations for svg paths

fernandocomet test
Moderator Tag

Go to solution Solved by Cassie,

Recommended Posts

Hi,

I am working in React + GSAP

I try to animate different paths (ids) from an svg asset (see image attached)

I am trying to animate the different paths on Hover/out

I am Following this example https://codesandbox.io/s/react-hover-forward-ref-pthnx but only the last one is being animated.

 

I think I have sintax problems.

Should I use a timeline instead?

 

My demo is here: https://codesandbox.io/s/little-circle-gsap-43pcbs?file=/src/App.js

 

Any help is welcome

 

 

Screenshot 2022-05-30 at 16.50.47.png

See the Pen App.js by s (@s) on CodePen

Edited by fernandocomet
bad demo url
Link to comment
Share on other sites

  • Solution

Hey there Fernando.

 

So you're trying to assign three different tweens to the same ref. Refs are like variables, that's like trying to assign three different numbers to one variable. Not gonna work! You could use a timeline, but you're doing the same thing to all three elements with a little delay so you can just use a stagger instead.

 

As for the React bit. It's best to use refs instead of trying to grab the DOM element directly.  But I'm getting error: 'Function components cannot be given refs' here. I'm not a React person but I assume because this function doesn't return an element and it returns functions instead you'd need to pass along the ref somehow. 

 

Here's a demo working, but not using refs.

 

https://codesandbox.io/s/little-circle-gsap-forked-cxrr5g?file=/src/App.js

We can't really offer React advice here but this community may be able to advise more on the ins and outs of ref forwarding.

 

Also, these guides may help!

 


Hope this helps!

  • Like 1
Link to comment
Share on other sites

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...