Jump to content
Search Community

Animating Stacked Backgrounds?

Learning test
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

Hi,

 

Sure you can. Since version 1.18.3 complex strings are possible for this type of properties. Check this codepen:

 

See the Pen oAIan by rhernando (@rhernando) on CodePen

 

The old way of doing it is commented out and just below is the new way.

 

Unfortunately you can't target each background separately, since you're animating a property of one element. Turns out that if you change the values the overwrite manager will cancel the current animation and start a new one, that's why in the sample all values are kept between each instance.

 

Here's the original CSS:

background-position: 100px 100px, 300px 200px, 500px 0px;

Here's the timeline:

tl
  .to(div1, 5, {backgroundPosition:"100px 100px, 300px 200px, 0px 0px", ease:Linear.easeNone})
  .to(div1, 2.5, {backgroundPosition:"0px 0px, 300px 200px, 0px 0px", ease:Linear.easeNone}, 2.5)
  .to(div1, 1, {backgroundPosition:"0px 0px, 100px 0px, 0px 0px", ease:Linear.easeNone}, 4);

The first instance moves the third background to zero-zero. The second moves the first background to zero-zero and the value for the third  is the same, otherwise the overwrite manager creates a new instance to the new values cancelling the previous instance. Finally the third instance moves the second background to 100-zero and the values of the other two backgrounds are the same.

 

If you need something different, then you'll have to stick with the old solution.

 

Happy Tweening!!

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