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

Share this post


Link to post
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?

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.

×