Jump to content
Search Community

Reposition after scale

rflc 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, this is my first post, and as such, this is a noob question. How can I reset an object's position to the top left corner of its parent after it has been scaled?

Edit: I was abled to solve it, I just needed to reset the transformOrigin property to the top left of the object.

See the Pen ZVEQMJ by rflc (@rflc) on CodePen

Link to comment
Share on other sites

@GreenSock Thank you so much. I actually have a related question, how can I re-position  an element without position:relative to the center of the screen? I had to position the element with only margins to float text around its initial (final) position. When I try:

 

TweenMax.set('#myElement', {left:"50%", top:"50%", yPercent:-50, xPercent:-50});

 

It actually moves the element to its top left (off screen)

Link to comment
Share on other sites

Hm, why wouldn't you just set position:relative? Do you have a demo? 

 

You could probably use getClientBoundingRect() and do the math to determine what the x/y values should be, but I noticed you're using relative units like vw/vh, so that won't really work in a responsive way when you do absolute transforms. Again, a super simple demo would be helpful. 

Link to comment
Share on other sites

Hi guys, sorry it is taken me this long. 

 

@mikel That's a very clever way to center elements. I need to translate to the center after the element is positioned with CSS in order to make the text to wrap around it. But I will save your technique for the future. Thanks!

 

@GreenSock Exactly, I need this to work in in a responsive design. Below is a demo, basically I want to animate an svg in the center of the screen and then scale it down and translate it back to its original position. Then I want to replace the svg with a picture and display the wrap around text. I worked around some issues and was able to set the parent to position: relative, but I'm still unable to center it in a responsive manner.

 

See the Pen madVGZ by rflc (@rflc) on CodePen

Link to comment
Share on other sites

11 hours ago, rflc said:

Exactly, I need this to work in in a responsive design. Below is a demo, basically I want to animate an svg in the center of the screen and then scale it down and translate it back to its original position. Then I want to replace the svg with a picture and display the wrap around text. I worked around some issues and was able to set the parent to position: relative, but I'm still unable to center it in a responsive manner.

 

 

@mikel's got the right idea. There's no rule that says you have to use same element. 

 

Check out how I'm using 3 different elements to pull off a full screen animation here. A "from" element, a "to" element, and a clone to animate between the two elements.

 

See the Pen WwgQEV?editors=1010 by osublake (@osublake) on CodePen

 

 

 

Another option is to reparent your element. The transition is completely seamless.

 

See the Pen REwRpZ by osublake (@osublake) on CodePen

 

 

 

 

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