Jump to content
GreenSock

ericshew

issue with animated height of a container

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 there,

 

I'm trying to create an accordion style box that will smoothly open before content appears within.  I'm trying to follow the in the footsteps of this post but have not met with success. Please review my codepen and provide any insight you have. thank you in advance.

See the Pen vJPZeB by ericshew (@ericshew) on CodePen

Link to comment
Share on other sites

Wow... this is perfect. Thank you so much! 
 
Could you explain or point me to documentation that can me understand line 12 (  tl.reversed(!tl.reversed())). I'm especially puzzled by the exclamation point. 
 
Thank you in advance
  • Like 1
Link to comment
Share on other sites

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

Ha! I knew you'd be along with a Professor Blake's Master Class in exclamation mark explanations. B)

  • Like 3
Link to comment
Share on other sites

Next week I'll cover the double exclamation mark. That confuses everybody when they see it.

  • 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

Hey Blake,

 

Glad to have you back and healthy after Irma. Hope you didn't take any serious damage. 

 

  • Like 1
Link to comment
Share on other sites

Thanks,

 

I'm all good. Just dealing with the usual stuff when a hurricane comes close by, power loss and a yard full of tree branches.

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