Jump to content
GreenSock

Dave Stewart

Animate one property dependant on another

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

Is it possible to animate a property of an object based on the value of something else?

 

I'd like to animate a parallax effect, so it would be useful to animate all but the top layer based on fractions of the top layer's left property.

 

 

Link to comment
Share on other sites

Sure, you would just use an onUpdate callback to modify any number of objects based on the properties of the element you are animating

 

var red = document.getElementById("redBox"),
    blue = document.getElementById("blueBox");

var t = TweenLite.to(red, 1, {left:550, onUpdate:parallax})

function parallax() {
  //the blue box will only travel half the distance
  blue.style.left = parseInt(red.style.left) * 0.5 + "px";
}
 

 

http://codepen.io/GreenSock/pen/xbjdD?editors=101

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