Jump to content


scale messing up my y translation

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



I'm trying to make an image gallery where the big image is transformed based on the thumbnail getBoundingClientRect() values. But I'm having trouble with the y transform value, I get the correct difference value but the scaling makes it look out of place. 


Check my Pen and u will see what I mean.

See the Pen VXMxKr?editors=0010 by ReGGae (@ReGGae) on CodePen

Link to comment
Share on other sites

getBoundingClientRect includes transforms. Sometimes it's better to use offfsetLeft/Top/Width/Height. And if scale is involved, you should probably animate the x/y values from the center instead of the top/left corner. Basically, calculate the x/y values based on where the transform origin is. By default, it's at the center for HTML elements.



  • Like 3
Link to comment
Share on other sites

You can either calculate the difference scale will cause or you can record values after applying scale. Check following demo where I calculate difference scale will cause, this will work only if your transformOrigin is center, otherwise you will need to do more calculations.


But what you are doing doesn't seem like right approach because if user scrolls, your element vanishes at wrong point. You will need to recalculate position in both direction to fix it.


See the Pen RMjNJJ?editors=1010 by Sahil89 (@Sahil89) on CodePen


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