02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School

Time to get Animated

Enough. Shall we animate? In this last lecture we animate.

Video Transcript

00:00welcome back so to complete this chapter we are going to want to use an
00:05animation library which is called green sock and we're going to be using it
00:09throughout the remainder of this course and we're going to use this library to
00:13animate and learn all the different capabilities of JavaScript and in the
00:17process also learn how to animate so what we want to do what you want to do
00:22is you want to go into the green sock site and download the G SAP library
00:28or you could use the CDN which is exactly what we're going to do in our case so
00:34I'm going to go ahead and what I want to do is I'm going to go into the script
00:37area and I'm going to create a new script tag and again I'm going to get
00:41rid of the type because it's just not valid for HTML5 we're not not that it's
00:47not valid you could put it there but it's just not needed once I do that I'm
00:52going to paste inside the actual path to the current version of our animation
00:58library now you don't have to memorize that just download it in our source
01:02files you could grab it from our final HTML file it is chapter 1.n that HTML
01:08you could just go ahead and grab the full path from there we're going to
01:12actually download the tween max which basically will preload most of the
01:16features of the G SAP library we're not going to talk too much about it
01:20we're just going to go ahead and use it but once we've loaded this in now we
01:25could start actually commencing into actions that are going to be able to be
01:31animatable which is kind of wicked so let's go ahead and do it it is going to
01:36be a little bit overwhelming but hey not too bad right hopefully so let's go
01:43ahead so first of all again just like we did previously we want to make sure
01:47that we only call this once the whole page is loaded so to do that I'm going to
01:51call my dollar function which is the jQuery function I'm going to open and
01:57close around bracket and send inside of it the document making sure that I'm
02:01wrapping my document in the jQuery wrapper next step is I want to call the
02:06ready function and the ready function I want to send into it my on ready so I'm
02:13going to go ahead and call the on ready and I am going to close it with the
02:19semicolon now I want to reuse this on ready so I'm just going to move this
02:24closing bracket thingy the commenting area there and I'm going to have it
02:29exposed so I could actually have access to it and I'll just comment down that
02:32alert because that's not what we actually want to happen instead of
02:36alerting what we want to do is we want to actually start animating now the
02:41process of animating in our case because we're using tween max we'll start
02:45with typing tween max and it's an uppercase T and uppercase M once we do
02:51that I'm going to type dot and I'm going to tell this tween max this animation
02:55library that I want to animate now the function that we'll call to animate in
03:00our case is going to be from now from basically says that take some element
03:07that are is on our stage and animate it from a different place now what element
03:13we want to use in our case we want to use our slide our slide itself we want to
03:20access it and send it in as the first parameter so to do that I'm going to
03:25call the star function again just like we did with our document below here but
03:31instead of that I'm going to send into a just a string and in that string I'm
03:37gonna send to it dot slide what that will do is it's gonna fetch any any it's
03:44gonna fetch any div layer or any any element really an HTML that has a class
03:50name of slide in our case there is only one slide so we don't have to worry about
03:55having multiple items animating so our first parameter from of our from is
04:00we're sending in that slide and we're wrapping it in with that dollar sign
04:04making sure that we'll have a way to approach it it's the most easy way to
04:08approach things once we're using jQuery all right we're learning a lot of stuff
04:13at the same time but don't worry we're gonna break a lot of it down as we go
04:28ahead now we're gonna put here a comma this is the first time we meet a comma
04:32inside of a from inside of a function statement and literally you know let me
04:37just put this here as as we're doing this it's gonna be tween max dot from
04:42and the first is what is animating the next is how long the next property is
04:53gonna be what what to animate all right and we're gonna see this in action so
05:00what is animating or what do we want to animate is the slide itself so that's a
05:06first thing we send in the slide the next thing is how long do we want it to
05:09animate in our case I wanted to animate for one second the next step is we
05:14want to send inside the different things of it we want to animate so just
05:19like within CSS if we go inside of our slide and find it in CSS we'll see that
05:24it has a height it has different could have different properties in our case
05:28what I want to do is I want to go to its position and I want to change its
05:33original position to do that I'm gonna create an object this is the first
05:37object we've ever created by opening a curly bracket and closing a curly
05:42bracket this will create a new object for me which inside of it I could send
05:46different properties now again this is probably complicated and it's fine it's
05:51gonna over the next few chapters we're gonna simplify things and as we learn
05:57different things more deeply they're gonna become easier and easier so again
06:01I'm gonna type your left because I want to animate the left property I'm gonna
06:05put here a colon and basically say to it what do I want to animate and I'm
06:10gonna put that as a string and say I want to animate it from position of 2,000
06:15pixels literally saying start the animation at position 2,000 and then
06:23animate into wherever you were and take one second to do it and I'm gonna just
06:28close a semicolon gonna save it if we go back into our browser and go to into
06:33our starter file and click on refresh you'll see that our animation is gonna
06:37animate all the way in now we definitely covered quite a lot of stuff but what I
06:42want to I want you to do now once you've seen this and I'm gonna give these to
06:46you as a practice as a little bit of homework this is complicated no question
06:51about it we're not gonna talk about the in and out of every single element here
06:55right now because we're gonna explore it as we progress into moving into the
06:59details in every chapter following through so it's okay if it's a little
07:04bit hard because things are gonna get easier in the next chapter but I want
07:08you to copy this function and go ahead right into your console and just paste
07:12it there and play around with the values so if I just type your enter again
07:17you'll see that it's gonna animate again but if I just click on the up
07:20arrow and I could go here and change it to animate from minus 1,000 pixels and
07:27you'll see that it's gonna animate from minus a thousand pixels I could go
07:32ahead and instead of animating the left I could animate the top and try to
07:35animate the top and we'll see that it's gonna animate from the top now all the
07:39properties that I could send inside of here are basically CSS properties so if
07:44you know CSS and you know a little bit of HTML even if the format here looks a
07:49little bit weird which it should if you've never programmed before you know
07:53some things are very very clear or should be that in the things that need
07:58to be clear when you're watching this beyond all this weird script which I'm
08:01sure is weird and one is this you need to know what this means this means in
08:06jQuery language it means get me the HTML element that has a class of slide or
08:13slide so it could be a few different elements in our case there's only one
08:16slide that has that name the next thing that should be obviously or obviously
08:21easy for you right now is how long the animation will take in our case it's
08:26one second now if it's not obvious to you go back into that console look at
08:31the slider and say hey let me put this into 10 seconds and let's see what
08:34happens if it's a 10 second animation and notice what will happen it's gonna
08:37take a really long time but at some point within those 10 seconds it's
08:41gonna animate its way down back into our screen the reason why it took so long is
08:46because we animated so far out because our top was at minus a thousand if we
08:52set it to minus 100 we would see it a lot closer if we put it in a plus even
08:57more so all right so that's really what you need to know you need to know what
09:02are you talking to how long are you gonna talk to and and then again the
09:06property that you're gonna talk to now don't worry about this format I know it
09:09looks weird for now just type it the way it is the most critical for you
09:13thing for you to understand at this stage is that this is the left
09:17property which correlates to the CSS left property and this is the value
09:21that would be put into it and just follow this follow literally without
09:26understanding fully the details of why right now because as we progress in each
09:30chapter and learn about the details of of the elements of the language we're gonna
09:36revisit the animations and see in the animations also how do we actually use
09:40them so we're gonna bounce back and forth between learning core competencies
09:45and programming and then seeing them in action so by the end of this course
09:49you'll be looking at this and it's gonna be easy for you completely easy for
09:53you all right and in any case if you have any question and something is not
09:57clear please feel free to comment in the comment box below we're always happy I'm
10:02always happy to answer any comment I'm always happy to hear from you in general
10:06so I'll give you a little bit of homework is create a animation that I
10:11have not used yet by taking this and maybe animating something of your own
10:16not the slide but something else or animating it longer or animating a
10:20property that we did not animate yet or not animate at all for example I'm gonna
10:26give you another example we could animate the height so if I go inside
10:30here and instead of the left and again I could just do it without changing the
10:33HTML just go right here and change the height I'm just gonna make sure what
10:38was the height originally it's gonna go down to 205 pixels so basically I'm
10:43saying start from a hundred and change your height to be to an animate your
10:47height and notice what's happening here now the height itself is because that
10:52the it's it's a position element so in our case it's basically changing the
10:58position of our element that's it I'm done for now and we're gonna see you in
11:03chapter two where we start really digging into different concepts of
11:07programming in JavaScript and seeing them animate so see you in the next
11:10lecture chapter

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!