Jump to content
Search Community

Animation timeline only once playable

Sacha test
Moderator Tag

Go to solution Solved by PointC,

Recommended Posts

Hey again, 

I'm working on my animated mobile navigation. Before this, I used one timeline, and did .reverse() when it closes, but I want to change the closing animation. So I create a second timeline. So for the code I use something like this:

const [open, setOpen] = setState(false);
const timeline1 = useRef();
const timeline2 = useRef();


useEffect(() => {
  if (open) {
    timeline1.play();
  } else {
    timeline2.play();
  }
}, [open]}
          
<button onClick={() => setOpen(!open)}>

This works fine when opening and closing the navigation once, but after that, the style wont change. It's like the timeline would have applied the "once: true" attribute. I tried recreating it in a sandbox, but there I'm having even more problems. I can't even make it work once, and I don't know why...

See the Pen by s (@s) on CodePen

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