Jump to content
GreenSock

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

Create timeline that will use dynamic values during progression

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

Greetings everyone! Thank you for taking the time to read my question.

 

I am using TweenLite and TimelineLite to create an animation timeline that simulates a user navigating a set of "sections".

 

When the user clicks a button, I create a tween that animates a percent value over the course of 0.3 seconds. On "update" of this tween, the "progress" of my timeline is set using TimelineLite.progress(x).
 
My issue is that if one of the sections is tweened for another reason to a different position on screen, when the timeline is progressed, the section immediately snaps back to where the timeline wants it, based on the original creation.
 
What I would like is that the position of the section would tween from it's new, updated position, to the endpoint defined in the timeline. Is this possible?
 
Here is some pseudo-code that should help illustrate my question.
 
var percentObj = {
  current: 0
};

var myTimeline = new TimelineLite();

// ----------
// Set starting positions

myTimeline.add(
  TweenLite.set($('#section1'), {
    'css': {
      'y': 0
    }
  }),
  TweenLite.set($('#section2'), {
    'css': {
      'y': 1000
    }
  }),
  TweenLite.set($('#section3'), {
    'css': {
      'y': 1000
    }
  })
);

// ----------
// Now that starting values are set,
// pause the timeline

myTimeline.pause();

// ----------
// Create future animations that
// will be triggered by the user

// Animate to section2
myTimeline.add(
  TweenLite.to($('#section2', 1, {
    'css': {
      'y': 0
    },
    'ease': 'Power1.easeInOut'
  })
);

// Animate to section3
myTimeline.add(
  TweenLite.to($('#section3', 1, {
    'css': {
      'y': 0
    },
    'ease': 'Power1.easeInOut'
  })
);

// ====================

function buttonClick() {
  TweenLite.to(percentObj, 0.3, {
    'current': 0.5,
    'onUpdate': updateProgress
  }
}

function updateProgress() {
  myTimeline.progress(percentObj.current);
}
Link to comment
Share on other sites

Hi and welcome to the GreenSock forums,

 

As Diaco suggested, a demo would be really helpful. 

Before you do that, just want to make sure that you know that you can tween the progress() of a timeline directly like

TweenLite.to(myTimeline, 1, {progress:0.5});

here is a demo: http://codepen.io/GreenSock/pen/yyzqOb?editors=001

 

Also, methods like TimelineMax.tweeTo() are really powerful, especially if you start using labels: http://greensock.com/docs/#/HTML5/GSAP/TimelineMax/tweenTo/

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

×