Jump to content
Search Community

Quickly jumping between different timeline animation on same elements causing overlaps in animation (demo code included)

brightpixels 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

https://jsfiddle.net/BrightPixels/xtoemsxf/

 

 

I have a set of buttons that trigger their own timeline animations on the same elements. Two related issues am having (detailed in the demo) is around how these different timeline animation interact (this is very simplified to help to debug issue). Am new to GSAP and the way am doing this may not be the best so would appreciate any better suggestions

See the Pen by BrightPixels (@BrightPixels) on CodePen

Link to comment
Share on other sites

Hi brightpixels,

 

Welcome to GreenSock Forums.

 

Its a small point - just position all tweens to the start (,0)

 

  four.addEventListener("click", function() {
  	var tl = new TimelineLite();
    tl.to(".chart-number", 2, {opacity: 0},0);
    tl.to(boxD, 2, {x: 0},0);
  })
  five.addEventListener("click", function() {
  	var tl = new TimelineLite();
    tl.to(boxD, 2, {x: 100},0);
    tl.to(".chart-number", 2, {opacity: 1},0);
  })
  six.addEventListener("click", function() {
  	var tl = new TimelineLite();
    tl.to(".chart-number", 2, {opacity: 0},0);
    tl.to(boxD, 2, {x: 200},0);
  })

 

 For more information : https://greensock.com/position-parameter

 

Happy tweening ...

Mikel

 

  • Like 2
Link to comment
Share on other sites

Hi Mikel, 

That's not an option for me, because I still want the number labels (".chart-number") to fade in, when the yellow line reaches the middle position. Also, when the line is moving away from the middle position, I want the number labels to fadeout first, then for the yellow line to move. If I follow your instructions, then everything plays at the same time.

Link to comment
Share on other sites

The way I understand, this is a bit of a logic puzzle.

You only need to wait for the labels to fade out if they are visible and if they are visible you have to wait til they fade out to play the animation that moves the bar.

 

I created a tween that fades the labels in and has an onReverseComplete callback that will trigger the next animation. The basic idea is I check to see if the labels animation has a progress > 1. If so I know I have to reverse that animation. When that animation reverses I trigger the next animation.

If that label animation does NOT have a progress > 1 I just skip the step of reversing it and move the bar.

 

It took me a little while to figure out and I'm not 100% sure its bullet proof, but give this a spin:

 

See the Pen eENWBq?editors=1010 by GreenSock (@GreenSock) on CodePen

 

 

 

below are 2 more demos that use the concept of waiting for an animation to reverse before another one begins:

See the Pen wMapvO?editors=0010 by MAW (@MAW) on CodePen

See the Pen XMygdo?editors=0010 by GreenSock (@GreenSock) on CodePen

 

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