Animating from here to there
It's time to crack our knuckles, and start animating. In this lesson we start our animation by getting introduced to the three most important functions in the GSAP library: TweenLite.to,TweenLite.from and TweenLite.fromTo. By the end of this lesson you'll be ready to animate. I can't wait to see what you will create.
Video Transcript
00:00This course is designed for intermediate users, so if you feel that we're going too fast
00:06then please check out our starter course because you'll feel a lot more at home in it and then
00:12come back to this course.
00:13With that said, this lesson we're going to dive right into the animation world and we're
00:16going to really explore the to, from, and from to in-depth where you're going to know
00:21everything you need to know about them.
00:23Let's get started.
00:24Let's get started with the tween light into our library.
00:27Now I forgot to mention, and I probably should, that most animations will probably, you'll
00:35need to have your CSS in them as well.
00:38In this lesson we're only going to use the tween light and really the difference is, and
00:42you can see in the file sizes as well, is that tween light comes with the core engine
00:48of the animation library.
00:50While the tween max basically encompasses inside of it the features of tween light plus many
00:57other features, and you can see that it's 23 kilobytes, and you can see why it's because
01:02it also adds into it a lot of other features.
01:07If we set it to be the, if I undo that for a second, I set the timeline light, we'll
01:11see that the timeline light encompasses what needs to load the tween light and the timeline
01:16light.
01:17If I set the timeline max, then I'm going to have to load up the tween light and the
01:21timeline max.
01:23Now with that said in general, the tween max is kind of like the item that bundles inside
01:28of it the most things, and we're going to start first by taking one thing at a time
01:33and only adding the features that we need.
01:36In this lecture, we don't have any capability of animating CSS.
01:40We literally only have an object that we could animate numeric properties in it.
01:46So let's start off and we'll start off by just going into our element here, going into
01:51our source files, and I'm going to go ahead and create a new tween light animation by setting
01:57the words tween light and the method two.
02:00Now the three properties that it's going to request is what do we want to animate?
02:04We can send inside an object, a direct object that we got from jQuery or a direct object
02:10that we got from our DOM, or we could send inside here a selector.
02:15In our case, we're going to use a selector.
02:17And what I'm going to do is I'm going to want to animate all images.
02:20In my case, there is only one image, so that's fine.
02:23And I'm going to have it animate for one second.
02:25That's the second property.
02:27And the third property is going to be an object, which we send to at the properties
02:30that we want to animate.
02:32In this case, I'm going to want to animate both my height and my width.
02:36So I'm going to go ahead and I'm going to animate my width.
02:40And you know what I'm going to set my width to zero, I'm going to set my height as well
02:44to zero.
02:45So my height and my width to zero.
02:50If I say this, if I go back into my application and I click on refresh, we're going to see
02:54that we're going to see that our image is going to collapse into itself and fade away as soon
03:01as we click on the refresh button.
03:04Now there are three most basic, most important functions you want to work with with all
03:08the tween light library elements.
03:10So I want to just walk through them really quickly.
03:13So you're familiar with them if you haven't watched our beginner course.
03:17So we have our tween light too.
03:19And I'm just going to copy this.
03:21I'm just going to comment this out.
03:23And we have also our from.
03:27Now we're in tween light from and then I could said I want to start from zero up to
03:31my width and my height.
03:32And if I save this and I click on refresh here, we're going to see that we're going
03:37to animate in our element.
03:41Now, next item that I want to look at is the from two and the from two looks very
03:46similarly to the to the basically to the two and to the from that they're just a mix
03:53of the two together.
03:54So when our first property is going to be from two, if our first property is going
03:58to be from where were we, our next property is going to be to where do we want to go.
04:02So I could go ahead and just copy this and set the values we want our values to
04:07be in the end.
04:07And if originally our size was one hundred and eighty set eighty seven for four
04:13eighty by one eighty seven.
04:15So for eighty by one eighty seven, we could say here instead of animating from
04:21zero, how about if we animate from let's say let's say we want to do this from a
04:26width of four hundred and sixty and we want to set the height originally to be
04:31one hundred and seventy.
04:31So we have here a little bit of a let me just change the view here.
04:36So we have a word wrap, right?
04:39So it doesn't.
04:40So we have a word wrap, but in general, I could break a line just to make it a
04:43little bit more readable.
04:46And what I'm going to do is instead of setting in my width to four eighty, I'm
04:49just going to go ahead and notch it up a little bit more so that way we could
04:52see that we could do completely different values that don't have to be
04:55connected in any way or form to the original sizes that we had previously.
05:00So if I save this and I go back into my application and click on refresh,
05:04we're going to see that now we're going to start from a bit smaller and we're
05:07going to stretch up.
05:08And obviously we could have done it the exact way around, but we're not going
05:12to do the exact way around.
05:13I just want to show one more thing is kind of like a quick recap or a quick
05:17how to work with Tween Lite in general.
05:20So we saw the two, we saw the from, we saw the from to the next thing that
05:24I want to do is I want to show you also how do you add properties that are
05:30a little bit more, I would say, relative to where you're at because these are
05:36very common behaviors with our animations.
05:39So for example, if we wanted to have our from animation to just be a little
05:43bit before our, oopsie, a little bit to start a little bit before where
05:48we are currently.
05:49So to do that, what we'll have to do is we'll send in a string instead of
05:53a number in this case, and I'm going to set here minus equals 20.
05:58And I can set here minus equals 20.
06:01And what that will do, it's going to subtract 20 from the value that we
06:04currently have and start from there.
06:07So if we start this from animation and this structure and we go back into our
06:12element here and click on refresh, we're going to see that we're going to start
06:16from those 20 pixels smaller and we're going to animate into its position.
06:20Now you literally could use this type of feature in any place where there's
06:24numbers, you could substitute those numbers with basically an equation
06:28that basically says, hey, I want you to go up or down.
06:30It could be also a plus.
06:32So in this case, if I want to show you also how to do a plus, I could go
06:34ahead here and just copy this from two.
06:37And in this from two, I could just set the from basically to set it with
06:41a minus 20, minus equal 20.
06:46And for the ending position, we could say, hey, I want this to grow by
06:5020 pixels from its current position.
06:52And really, in this case, we're going to basically have an animation that
06:55is of 40 pixels, basically in width and height.
06:59And if we go on and click on refresh there, we should see now the
07:02animation going through a longer process, a longer animation, a little
07:07bit bigger than what it was by default.
07:10So there you go.
07:10That's that that's tween light and basically these functions, the two
07:15from and from two are available on both tween light and tween max.
07:21And although we're going to be focusing right now on tween light, everything
07:24we're doing here is viable and the same for tween max with the only
07:29difference is that if you go inside of your, if you go and look inside
07:33of this library here and we're seeing here that tween max area where
07:36there's a lot of plugins and a lot of extras and a lot of things
07:39that are preloaded by default with the tween light, they are not
07:43preloaded by default.
07:45So if I want to use CSS, I have to actually import it.
07:48If I want to use any extra features, I'm going to have to import them.
07:51Now, obviously, if you don't need those extra features, then don't load
07:55the, all these things up.
07:56And that's exactly what we're going to do in our next lecture.
07:59We're going to stick to having no, no features and no nothing.
08:02And just take that tween light library and create some sort of animation
08:06with it without involving any extra properties.
08:10So let's jump right in and do that in the next lecture.
