Jump to content
Search Community

How to animate a list of object/properties to their original values ?

flunch test
Moderator Tag

Go to solution Solved by Carl,

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

Hello, 

I'd like to create a timeline that at some point sets back initial properties on objects but without doing the animation backward (no reverse())

Ex. i have multiple boxes with different predefined colors and opacity.

I would like to animate them all to white and opacity:1 and scale:2

Then setting scale to 0

And then back to initial positions

 

ex. : 

tl.to(".box", 1, {backgroundColor:'#ffffff', opacity:0,scale:2})
.to(".box", 0, {scale:0})
.to(".box", 1, {backgroundColor:'Initial-Color?', opacity:'Initial-Opacity?',scale:1});
 
Thanks a lot !

See the Pen Wvworo by gavrochelegnou (@gavrochelegnou) on CodePen

Link to comment
Share on other sites

  • Solution

Hi and welcome to the GreenSock forums,
 

Thanks for providing the demo. Very helpful.

 

Its an interesting challenge. What first comes to mind is something that involves recording the initial values and storing them on the DOM element like 

box1.background="blue" //or use getComputedStyle
box1.opacity=0.5

and then tweening back to those values like

.to(box1, 2, {backgroundColor:box1.background});

It can turn into a bit of work.

 

However a much easier solution is to use clearProps (see CSSPlugin docs) to remove all the inline styles and then tween from() whatever values you had tweened to() like this

 

tl.to(".box", 2, {backgroundColor:'#ffffff', opacity:0, scale:2})
  .set(".box", {scale:0})
//remove the inline styles of your choice that GSAP has animated (or use "all")
.set(".box", {clearProps:"backgroundColor,opacity,scale"}, "+=1")  
//tween from the values you want to the normal css values
.from(".box", 1, {backgroundColor:'#ffffff', opacity:0, scale:2, immediateRender:false});

http://codepen.io/GreenSock/pen/jPqyoo?editors=001

 

*that last tween you can tween from any values you like (they don't have to be the same ones you tweened to).

So the last tween could be 

.from(".box", 1, {opacity:0, scale:0, immediateRender:false});

which will match Shaun's result.

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