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

Our first tween

Before moving into the club related features lets see GSAP in action. By the end of this lesson, you will know how to create a GSAP animation.

Video Transcript

00:02Okay, before we move into the world of the club,
00:06I wanted to get you more familiar
00:09with tweens themselves and how do you tween in general.
00:12Most of your animations are gonna be things
00:14that are sitting on your browser.
00:17And in our case, the easiest thing we'd probably do
00:19if we wanna do any animation is figure out,
00:22if we go into our inspector, very important
00:24that you'll always have that open
00:25because it just makes life easier.
00:27And figure out what you wanna animate.
00:30In our case, I really wanna animate
00:31this blue background to basically drop in
00:34and not be static.
00:36So our application will start with a little bit of a slide.
00:39And literally what I'm doing is I'm finding
00:41what is animatable.
00:42In our case, you can see the slider itself has its height
00:45and I could play around with that value
00:47and you can see that I could start
00:48from it being completely not there
00:50and I could have it animate in to its position,
00:53which is exactly what I wanna do
00:55through the library itself.
00:58So let's go ahead and do it.
00:59It's incredibly easy.
01:00All I need to do is once I make sure
01:02that I loaded up my tween-max
01:04is going right into my JavaScript file,
01:07that source file that we said we were gonna work in,
01:09in my hello world.
01:11And I'm just gonna create here a new function.
01:14I'm just gonna call this hello, oops, excuse me.
01:19I'm gonna call this hello worldy.
01:22All right, so hello world,
01:23but if we call this basic hello,
01:25let's call it basic hello.
01:28And basic hello is gonna do just literally
01:31a very simple thing.
01:32I'm just gonna very quickly create that function,
01:33basic hello.
01:36And the reason why I'm also separating these functions
01:38into functions is just from a functionality level
01:40so I could just turn off specific videos
01:43as I move on to different videos.
01:44That way you could find those functions
01:46and they won't have to overlap with each other.
01:49All right, so with basic hello,
01:50what I wanna do is I just literally wanna just
01:53call tween-max and I'm gonna tell it
01:55that I wanna make an animation.
01:57Now there's two most common animation
01:59which is the to or the from
02:01and there's also a from to.
02:03We're just gonna look at from right now
02:05but the logic and you can see in the documentation
02:07is very, very simple and you're incredibly welcome
02:13to join our training of over 24 hours
02:15that will teach you a lot about animation
02:18and programming in general which you'll find a link
02:20for that in the bottom of this video.
02:24So let's go ahead.
02:25So I'm gonna create the tween-max from
02:27and I'm gonna first decide what do I wanna animate
02:30and to be able to decide that I'm gonna go back
02:32into my browser for a second and just look at what it is
02:35and in this case, I wanna change the values
02:37inside of the CSS rule of slider.
02:40So to do that, all I really have to do
02:42is use the same CSS rules that I have
02:45and apply them directly inside as our first value as a string.
02:50So I'm gonna call your slider
02:52and that's gonna be my first parameter.
02:54The second parameter that I wanna put in
02:56is gonna be the amount of time which will be in seconds
02:58and in this case, I want it to be one second.
03:01And last but not least, I wanna create an object
03:04and in that object, define what are the properties
03:07that I wanna animate.
03:08In this case, we know that I wanna animate
03:10the property of height and I want it to actually start
03:14from the value of zero pixels.
03:17Now, if any of this looks unfamiliar
03:20from a level of syntax, then please do join
03:23our learning JavaScript through animation level one
03:26which you'll find a link to in the bottom of this video
03:28where we'll teach you everything about functions
03:31and variables and a lot of other things
03:33that will give you a lot of power
03:35when it comes down to creating animations.
03:37Very important to know some core skills in JavaScript
03:40to use any library even though the gsap library
03:43is incredibly easy and intuitive once you get used to it.
03:48Now, the next thing that I wanna do
03:49even before we start animating is I wanna make sure
03:52that my text that I have here won't be visible
03:55because I just wanna have it invisible initially
03:59when my application starts.
04:00So to do that, I have to first target and find
04:02where is that element sitting
04:04and it's actually sitting inside of this container,
04:07inside of slider containers,
04:08quite a lot of different elements here
04:10and you'll find it's inside of the slide and it's a h1.
04:14So I'm gonna go ahead and create a rule for that as well
04:18and if I come back right in here,
04:19I'm gonna go here into tween max again
04:21but this time I'm gonna use the function set
04:23which doesn't use any animation but instead of that,
04:26defines a property without a time
04:28and then the resource immediately defines that property
04:30and in this case, I wanna call the slide
04:33and I wanna be the h1 inside of the slide
04:35so it's literally exactly the way you define CSS rules.
04:39Last but not least is we wanna go ahead
04:41and say what do we wanna do here
04:43and I wanna make sure that my display is set to none
04:46and voila, that's all I really have to do
04:49to run my application.
04:50Now, one more thing I just wanna say
04:52before we wrap this up is that I could send here
04:54directly a string or if you're already custom
04:57to working with jQuery and they already have a jQuery object,
05:00you are more than encouraged to send that jQuery object
05:04directly inside, all right?
05:06So that's it and let's just see what we did,
05:08what we created, let's make sure
05:10that we don't have any errors.
05:11I'm gonna run my application one time
05:13and you'll see that it slides in,
05:15the copy is not there, we don't have any errors
05:18and that completes our basic overview
05:20of the Green Sock Library.
05:23In the following few lessons, we're gonna assume
05:25that you have a basic familiarity with JavaScript
05:27and with the Green Sock Library,
05:30so if you don't, please do make sure
05:31that you check out our video on the bottom there
05:34and see you in the next chapter
05:35where we start exploring the club features.

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!