Jump to content
Search Community

Accordion Flip with Timeline on open

intex test
Moderator Tag

Recommended Posts

I want to add a timeline animation to an accordion open click and am relatively happy this Pen works fine.  However I can't help but feel how I determine the accordion is opening or closing is hacky.  Also I feel I should using this:
var accordion_tl = gsap.timeline({paused:true});

 

And then this where my current timeline is:
gsap.timeline().add(accordion_tl.play());

 

But anything I try doesn't work as I want.  The current code does exactly what I want but curious to know if there is a better implementation.

See the Pen bGMWJPy by paulc123 (@paulc123) on CodePen

Link to comment
Share on other sites

Hi,

 

This seems to be more concise and perhaps closer to what you're trying to do:

See the Pen ExLXEWd by GreenSock (@GreenSock) on CodePen

 

Also I added this particular part to prevent a click event while the content Flip animation is happening:

if (Flip.isFlipping(el.querySelector(".accordion-content"))) {
  return;
}

Normally is a good idea to store animations that can be toggled several  times in a constant or variable so you can play/reverse them without any issues. This is a more particular case though since Flip has to do a few other things, so it's a good idea to use fromTo instances to prevent odd ending values when the toggle action is triggered too many times.

 

Happy Tweening!!!

Link to comment
Share on other sites

Wow thanks Rodrigo, that is so much neater than before.  I have used fromTo before so should have thought of that.  But isFlipping I haven't seen, and can see how useful it is.  I did wonder whether storing the animation was correct and tried gsap.timeline().add(textTL.reverse(0));  But obviously I don't want to reverse it, just close the accordion.  Anyway you've made everything clear.

 

Much appreciated!!!

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