Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
Daniel Hult

Animate div width from center

Recommended Posts

Hi!

How can I make a div go from 0 to 100% width, and also from the center? I don't want to scale the whole thing - I just want it to animate the width.

Also just wanted to say that I am super happy with both the products and the support here is amazing! Thank you guys for such a good product and community :)

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

I want to do an animated welcome page and on load the whole screen (the div element) should start from the middle and animate out to the sides. Is this not possible?

Link to comment
Share on other sites

If you want to animate width from the center, then you're going to have to move it the left at the same time, preferably using x instead of left. You would move it half the width you're animating.

 

  • Like 2
Link to comment
Share on other sites

I just made a quick codepen here of what Im making. Why does the svg logo behave so weird? Like flickering?

See the Pen WVJdzG by daniel-hult (@daniel-hult) on CodePen

Link to comment
Share on other sites

1 hour ago, Daniel Hult said:

Also just wanted to say that I am super happy with both the products and the support here is amazing! Thank you guys for such a good product and community :)

Love hearing that!

 

@mikel offered a great solution. Here's another example of basically the same idea: 

See the Pen 8586b002d06797032bb34a647adc01b2 by GreenSock (@GreenSock) on CodePen

  • Like 1
Link to comment
Share on other sites

26 minutes ago, Daniel Hult said:

Why does the svg logo behave so weird? Like flickering?

Short answer: its container is being moved and changing width so it's hard for the browser to properly calculate the position of the element.

 

I'd recommend placing it outside of the background that's animating.

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