Jump to content
Search Community

issue with animated height of a container

ericshew test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Hi @ericshew :)

 

The exclamation mark is a logical operator that means not. Blake is toggling the orientation with that line. More info in the reversed() docs here:

https://greensock.com/docs/TweenMax/reversed()

 

Another good example you'll probably use a lot is checking whether a tween isActive() or more accurately - not active when allowing some new animation to happen. 

 

  if(!yourTween.isActive()) {
    //only do stuff if the tween is not active
  }

 

Here's some more info about the isActive() method in case you're not familiar with it.

https://greensock.com/docs/TweenMax/isActive()

 

Hopefully that helps. Happy tweening. 

:)

  • Like 3
Link to comment
Share on other sites

Hi @ericshew

 

@PointC did a pretty good job covering most of it. An exclamation mark in JavaScript negates something. So a truthy values becomes false, and a falsy value becomes true. That makes it really easy to toggle a value.

 

var isReversed = false;

isReversed = !isReversed; // now it's true
isReversed = !isReversed; // now it's false
isReversed = !isReversed; // now it's true

 

To understand the double reversed statement, you should look at the docs first. Like most GSAP methods, reversed() can be used to get and set a value. So I'm getting the reversed state of the timeline, negating it, and then setting the reversed state.

 

So what I did is the same thing as doing this.

var isReversed = !tl.reversed();
tl.reversed(isReversed);

 

Here's a thread where I explain that and some other tricks in greater detail. There's an accordion demo somewhere in that thread, which might help you out.

 

  • Like 3
Link to comment
Share on other sites

Thanks! This makes a lot of sense.  It is a very elegant solution. 

 

My last question is about the .reverse statement on line 9.  it looks like what is happening that the whole timeline sequence completes and then reverses and returns to the beginning.  If that's correct, then how come it takes place instantly. It seems that the delays built into the other lines are not having any effect on its initial run through. Thank you again for your help. 

Link to comment
Share on other sites

  • 2 weeks later...

Hi @ericshew

 

Sorry, I lost some days due to Hurricane Irma.

 

I'm calling reverse at the end for a very specific reason, so the progress stays at 0 when I call reverse, but it is not affected by any delays as it's not part of the timeline. The method chaining looks like its part of the timeline, but it gets executed as soon as that line of code is read by the browser. 

 

I could have called reverse elsewhere in the code and it will still work out the same. Check out this demo. Click anywhere to reverse the timeline.

 

 

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