Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
kevinpasnik

TweenMax scale div and maintain CSS Top and Left position

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}}); 

 

or

 

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 post
Share on other sites

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

×