Jump to content
GreenSock

Aizy

Animate the height and width of a div from center.

Go to solution Solved by SteveS,

Recommended Posts

I am trying to replicate the button (watch how it works button) animation on this site: iBuyer.com | Sell Your House Fast With An Instant Cash Offer. .
I tried animating the width and padding but I'm unable to trigger the animation from the center, mine starts from the corner as you can see. Also I am having trouble creating the first part of the animation which I believe is height being animated from 0 to something like a 100.

 

P.S. I've added setTimeout to delay the second animation (the center text), which should only get trigger once the first two phases of the animation are completed.

See the Pen LYQqbdL by Aizazulhaq (@Aizazulhaq) on CodePen

Link to comment
Share on other sites

  • Solution

Animate scale, not padding. Set the transform origin to center. You are also using TweenMax. It's recommended that you upgrade to a more recent version of GSAP and use current conventions for writing tweens.

Here's a codepen:

See the Pen ExQrWRz by SteveSDaBest (@SteveSDaBest) on CodePen

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

@SteveS I've edited the codepen and added gsap.fromTo and I'm animating scale instead of padding. Now it's animating from the center but not quiet the way I want it to. I want it to expand from the center. 

Link to comment
Share on other sites

It is expanding from its center, unless I'm not understanding.

Link to comment
Share on other sites

11 minutes ago, Aizy said:

@SteveS I've edited the codepen and added gsap.fromTo and I'm animating scale instead of padding. Now it's animating from the center but not quiet the way I want it to. I want it to expand from the center. 

Can you elaborate? I'm in the same boat as @SteveS - it's doing exactly what I'd expect. Are you saying you want it to expand from the "center" of something else rather than itself? 

 

You never need a setTimeout() with GSAP - you can simply set a delay on the animation or put it into a timeline where you can easily choreograph timings with the position parameter

 

Here's an option with a timeline: 

See the Pen abqXWJN?editors=0010 by GreenSock (@GreenSock) on CodePen

  • Like 2
Link to comment
Share on other sites

I think @Aizy is referring to the updated pen in which scale has been used rather than scaleX and/or scaleY.

 

@Aizy see how @SteveS has used a combination of scaleY and then scaleX to achieve the desired outcome? You'll also want to remove that scale(0) in your CSS. 

 

Happy tweening.

:)

  • Like 2
Link to comment
Share on other sites

@SteveS, @GreenSock I was referring to my edited code pen where I used `scale` instead of `scaleX` and `scaleY`. The solution @SteveSprovided works the way I want. and I have marked it as a solution. Thank you.

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