Jump to content
Search Community

GSAP Timeline working incorrect in modal close/open

DanielLav test
Moderator Tag

Go to solution Solved by Cassie,

Recommended Posts

Hello GSAP community 👋 I had a problem with the animation being quite light I think xD. But I spent hours and couldn't implement it.

 

I am attaching my codepen so you can see my code:

 

I'm creating an animation for a modal window to appear to select the language version of the site. My animation works correctly when opening and closing the very first time, but as soon as I try to open/close my modal window again the animation breaks.

 

I think it has to do with this line of code

langContainer = $(this).siblings('.lang-container')

I use it because on my site there are several places with a language switch and I don't want them all to open at once.

 

I also need that when a modal window is open, if the user clicks anywhere on the site except the modal window itself, then it closes.

 

Perhaps you have ideas on how this can be done? I tried to simply add a reverse timeline when clicking on a $document, but with this approach it will also capture the modal window.

 

Write if you need more information.

I will be incredibly grateful for your help!

See the Pen wvbyXQW by ProjectDCL (@ProjectDCL) on CodePen

  • Like 1
Link to comment
Share on other sites

  • Solution

Heya!

 

So a loop is really what you want here, I'm pretty rusty with jQuery, but something like this?

See the Pen QWRQZxd?editors=0011 by GreenSock (@GreenSock) on CodePen



You can bind the timeline to the element and then when there's a click on the document (that isn't the lang element), do a loop again, check if any of them are open and if so, close them.

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