Jump to content
Search Community

Calculate post-transform bounding box

Mia+Lily 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 GSAP people!

 

I need to animate an element to the closest off-screen position. To do that, I need to know the element bounding box, so I can make sure it's fully hidden. In most cases `getBoundingClientRect` works just fine, but the element can also have some transforms applied and even its transform origin changed. See the codepen for the idea.

 

As GSAP works heavily with transforms, I hope you'd be able to point me to the right direction. 

Is there a way to get the full transform matrix? I should be able to feed it the bounding box corners and get the real position.

Or is there anything else you'd recommend?

 

Thanks!

David

See the Pen gQMYjg by anon (@anon) on CodePen

Link to comment
Share on other sites

2 hours ago, Mia+Lily said:

In most cases `getBoundingClientRect` works just fine, but the element can also have some transforms applied and even its transform origin changed.

 

 

I'm pretty sure getBoundingClientRect works in all cases. The circle looks weird because it doesn't have corners, but it's correct.

 

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

 

 

 

  • Like 5
  • 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.
×
×
  • Create New...