From and to the timeline
Just like the other tween classes in the GSAP Library, so do the timelines(TimelineLite/TimelineMax) have a plethora of methods to create animations directly. In this lesson, we will explore the to(), from(), toFrom() methods of the TimeineLite library.
Video Transcript
00:00Just like tween light and tween max oto timeline light and max have the two from and from two
00:07They work a little bit differently, but very similarly and that's what we're going to be exploring in this back to animating
00:14We have already our stage ready. We have our images of the dog on display
00:19What I want to do next is actually animate them into their position and to do that
00:23We're going to just start with a very simple animation, but we need a timeline for that
00:27So we're going to go ahead and create a timeline and what I want to do is I want to create that timeline
00:31Inside of that geek tube, so I'm going to go ahead here and just create that geek tube
00:37I'll just call it TL for timeline, and I'm just going to create a new
00:42time
00:45light
00:46All right, so once we created the timeline now we could start adding things into it
00:51Now an important thing is that a timeline automatically is always playing so as soon as you add something into the timeline
00:58It will continue playing now the reason why this is important is because our image is not going to all be ready at the same time
01:04And there might be a scenario where it takes it more than
01:08X amount of time of our animation to load
01:10But it doesn't really matter because all we could all we really need to do is just approach our timeline and just add
01:16Like we did before or for now what I want to do in this lesson
01:20I want to walk through three methods that will be very familiar from
01:25Working with the tween light and tween max is the two method the from method and the from two
01:31So let's start with the two the two again. We'll accept the object that we're animating which is the image
01:35Which is this the net second parameter is how long will the animation be in our case?
01:41We want the animation to take about let's say
01:44Let's make it one second the next thing is we want to define
01:48What are we animating and if we want to animate it to a specific position?
01:52We've a good idea would probably be to do this clip because we want to animate it to that position
01:57We want it to end in that position
01:59so I'm going to go ahead here and just wrap it up in an object and just paste that clip right there and
02:04Then I could go ahead and just change the values that we have here to be basically
02:090 0 0 0 0 0 like that will have a
02:12Different starting point in a different starting and and it should animate itself in that's all I really had to do to get my
02:19animation going which was my this the amount of time and the object very similar to if I would create actually the tween itself because
02:26What's happening is behind the scenes?
02:27It's creating a new tween light animation because we're working with the timeline light if we were working with the timeline max
02:34And it would create a new
02:35Timeline max well it would create a new tween max
02:38So if I go ahead and save this and go back into my application and click on refresh
02:41We should see that we should have your very interesting animation going on and it's going to animate each one for a second one
02:48After each other and it doesn't really matter if our elements were not loaded in advance if they weren't ready
02:55Then it'll just continue on and load it when they are ready now if to prove that point
02:59I could go ahead and make this animation really
03:02blazing fast 0.1 seconds to show you that it will still work and if I go ahead here and click on refresh
03:08It should still work. It's gonna as soon as it comes in it will basically go to its position now
03:14I'm gonna keep it at one because I want to talk about another something which is the sec two other them the
03:20Final parameter more accurately of this and of this item so we saw the the object we saw how long we saw
03:27What is animating and the last property is the?
03:31Position in time you remember that position from the add function so we said by default it goes to position zero
03:37And I could say I want it to be with a delay of two seconds or I could say I want it to come earlier on
03:43and if I go ahead and click on refresh here it should go ahead here and
03:47Create a delay of two seconds between each iteration
03:50We won't wait through because it would take too long and we could also
03:54Subtract and we can't put a negative value
03:57But in this case if I go from one and we're already in position zero right now going to minus two
04:02We'll just make sure that it starts at zero so the first two items theoretically should have it almost parallel
04:08While all other I animations will happen later on so we go ahead and click and refresh this is going to be a very interesting
04:15Example you're going to see that these animations are going to start later on because they weren't ready
04:20They weren't there these items were it creates obviously this is not a very logical animation
04:25We probably would want to subtract only by a portion of that value such as zero to five
04:29So there's a little bit of an overlap between the animations and not more than that and there you go
04:36So that's the two and I want to go ahead really quickly and move to the from because this is a very familiar
04:42Construct, so I'm just going to go ahead and comment this out, and I want to move on to the to the
04:48From and the from works in the exact same way really, so I'm just going to copy this and
04:53I'm going to paste it right here, but I'm just going to switch around between the values that we're sending
04:58So I'm just going to grab this value cut it out
05:02Send it right here, and I'm going to just cut that
05:07and paste it inside instead
05:09Because we're literally just doing the exact opposite and I could go ahead and just set here a from the same type of
05:15All the parameters that we talked about are all exactly the same with the two and the from and if I go ahead and click on
05:21Refresher we're going to see something very very disturbing, but we're not going to fix it right now
05:26We'll fix it in the next lesson. You'll see that there's like this jitter going on here
05:30Now the jitter that excuse me the jitter that's going on here is because it's actually going to run
05:36under our element
05:38Before we actually start this from animation and this from animation only in the beginning of the animation is literally resetting the information
05:46And it's not actually having it doesn't have a chance to reset the information
05:50Before it's actually entered in and that's basically our problem that we have here which we're not going to solve right now
05:55We're going to solve in the next lesson, but before we wrap up this lesson
06:00I want to show you also the last option which was the from to and
06:04I'm just going to comment out the clipping because we're going to put all the clipping now inside of the from to and
06:10literally
06:11Go ahead and copy this
06:13Same exact rules apply only the first parameter is the from object and the second parameter would be the
06:20Well the the to object which would basically be this beautiful
06:24clip we got right here and I'm just going to make sure that it's inside of an object and
06:30Paste that right in there. So just to make things a little bit more visually clean. Let me just
06:36Comment break lines here a bit so we could see this more vividly more clearly
06:40so we could see that the first parameter is the object itself then how long then the oh we have your from to we said and
06:48then we have the from variables the two variables and the duration of the
06:54Off setting the position that we're placing and that said that's the third item and if we go and run this again
07:00we're going to see that it's going to run in
07:02A very very crazy matter and the reason is again is because we're basically what's going on here
07:09When we're configuring and setting our value we we're not setting a clip
07:13So we're basically positioning our item immediately in full display
07:17And that's what's happening that is that flash that we have there by the time we get to this line
07:23And it's actually doing this it already rendered it and we definitely have an issue here that we want to solve
07:29We didn't have that problem though when we were setting our clip to be 0-0 in the beginning because we made sure that our item
07:36was invisible
07:37So we're going to see in the next lesson. How do we solve this type of issue?
07:40How could we avoid a scenario where we have these jumping arounds that we really don't want to happen?
07:46And that's what we're going to look at in the next lesson
