Jump to content
Search Community

Add timeline after autoRemoveChildren

iamjonas test
Moderator Tag

Recommended Posts

Seems like an issue with overwriting GSAP values while already having values set. I don't have time to debug this for you ad the moment, but I know I personally had the same issue while wanting to create a slider using GSAP. I had tried to build it many different ways before settling on the approach below. 

 

This just creates the animation between any two slides each time and then resetting all the values again (maybe this is easier now with .revert() https://greensock.com/docs/v3/GSAP/Timeline/revert()). My initial plan was also to create all the timelines on page load and then animating those timelines, but this will as you have found results in conflicts that you then have to find and fix. It's a completely different setup, but I hope you can glean some knowledge from it. 

 

See the Pen GREebPK?editors=0010 by mvaneijgen (@mvaneijgen) on CodePen

  • Like 5
Link to comment
Share on other sites

Hi @iamjonas and welcome to the GreenSock forums,

 

I wasn't able to follow your code closely enough to really ascertain if there was a problem with autoRemove children, however as a general principle I avoid timeline manipulation like this when dealing with user interactivity.

 

It is usually much more bullet-proof to generate your animations fresh on the fly then move existing timelines into other timelines while trying to restart the animations that you just added.

 

As @mvaneijgen noted these things can be troublesome until you find the "right way" and along that journey we all try things that seem like they should work but are more complicated than necessary so don't sweat it ;)

 

I haven't used jQuery in awhile but I think you can get closer to accomplishing your goal with this type of approach

 

See the Pen ExpjWGj?editors=1011 by snorkltv (@snorkltv) on CodePen

 

The app starts out by defining a currentContent variable that will eventually point to the current content on the screen.

Until anyone clicks anything, currentContent is undefined.

 

The basic premise is that every time you click a button you get its index and then see if the item in the contents jQuery Object at that index is the same as the  "currentContent" (content that is displayed)

 

if they are the same then nothing needs to be done.

 

if they are not the same then pass the object that is in the contents jQuery object at that index into the animateIn() function.

 

The animateIn() function then animates in the thing it should and if there was a previous currentContent it animates that thing out. The thing you just animated in becomes the new currentObject. rinse and repeat.

 

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