Jump to content
Search Community

TweenMax scale div and maintain CSS Top and Left position

kevinpasnik test
Moderator Tag

Go to solution Solved by Jonathan,

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

Is it possibe to scale a div with TweenMax but I would like to maintain or reset the CSS top and left position?  Below are a few failed attempts.  It seems TweenMax always scales from the center point.


TweenMax.fromTo('#div-name', 2, {scaleX:.5, scaleY:.5}, {css:{top:0, left:0}}); 




TweenMax.to('#div-name', 2, {scaleX:.5, scaleY:.5});
$("#div-name").css({ top: '0px', left: '0px' });
The Codepen URL shows the red div scaling but not maintaining the top: 0 and left: 0 desired position.

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

Link to comment
Share on other sites

  • Solution

Hello kevinpasnik, and Welcome to the GreenSock Forum!


To scale from the center point you use the CSS property transform-origin (transformOrigin) .. so you could do this:

// set transform origin to top left
TweenMax.set('#div-name', {transformOrigin:"0% 0%"}); 
// since scaleX and scaleY are the same you can just use scale
TweenMax.to('#div-name', 2, {scale:.5}); 


I am also using GSAP set() method to set properties:


set() : http://greensock.com/docs/#/HTML5/GSAP/TweenMax/set/


Does that help? :)

  • Like 1
Link to comment
Share on other sites

  • 6 months later...

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