Integrating the CSSPlugin
Until now we worked without any Plugins. In this chapter we'll break into the world of plugins as we explore the features of the CSSPlugin. By the end of this course, you will know how to integrate plugins when working with the GreenSock JS library. In this lesson, we will expore the set up and end with a CSS based animation.
Video Transcript
00:01Chapter two, I don't know why I love doing this this there's I should get this into my regular talk when I speak
00:07Well, how do you do? So how do you do it is chapter two? I am excited
00:12I hope you're excited as well. This chapter is gonna be dedicated to CSS
00:16Although our course is not about CSS, so we're not gonna learn every single thing you could do with CSS
00:21We're gonna look at some main features
00:23Traveling through first how to configure and set up your CSS plug-in and do the first little things with it
00:30So let's jump right in there. Our goal is to create a little cool widget that hopefully you'll take part of so
00:37After you finish this chapter if you want to be able to add something to your resume that is incredibly cool
00:42Come up with a really cool animation. That's simple that would work for zero to geek calm
00:47And if we love it
00:49we're gonna pick one item out of the stuff that are offered up and the one that we love will integrate into our site and
00:55Then you could add that into your resume and then you could show it to the jobs and whatever that you created something that ended
01:00It up on zero to geek calm. So let's get started
01:04We're gonna show you what our project is throughout this chapter and then it's gonna be up to you
01:08If you pick up the glove and decide you're gonna do something with it. Let's get started
01:13Animating I added a really cool kind of simple menu
01:17That is a derivative of something on our website zero geek calm
01:22And I wanted to animate it with you because it is although it's pretty it'd be really prettier if it had some interaction
01:29Now one thing that I want to do is I want to first have like the starter animation or maybe having a complete background
01:36So if I just show this to you if I'm just gonna inspect this
01:40HTML here for a second and I'll just search for our
01:44component here
01:45I'll just start with the blue element and
01:47Really what I'm looking for is that background what I want to do is I want to basically
01:51Animate that blue background and basically have it start from basically a full screen
01:57Have it start from there and just have it animate in as the application starts to drive a little bit of our eye
02:04to that section
02:06And we're gonna do that with all the three basically
02:08It's gonna make those items more noticeable as there aren't any other components on the page
02:13Which by the way, if we go there on to my site on to zero to geek calm
02:18You're gonna find the full component in its
02:21Habitat
02:22You'll find that in the courses sections you'll see that right here
02:24And this is the only component that is animating which this is basically step two
02:29We want to create some sort of nice little animation where you roll over and you roll out
02:34But initially what I want is that our application to start where it's completely
02:38on that rolled over in state
02:42Supposedly and have it animate into that right position that it needs to be in and it's exactly what we're gonna do in this
02:50Lesson well in this lesson we're gonna start from this area animating it out
02:54Now to make that happen and what we're gonna have to do is we're gonna have to go back on to green talk if you
02:59Didn't download the full source files and click on to download GSAP
03:03We're not gonna actually download it
03:05But we're gonna go ahead and customize it and I'm just gonna show this really quickly because we talked about this this time around
03:10I just want to add the CSS plug-in because I want to start animating CSS properties
03:15So make sure that you select that CSS property and that you download and copy this file
03:21Or down you can or download the file all the files or just select the files that you're using and we'll use their live host
03:27So I'm gonna go ahead into my source files and what I'm gonna do next is I'm just gonna add that into my file
03:33And notice that I'm working on the chapter to that end
03:36I'm not gonna remind you every time but you're gonna start from chapter to start that way
03:40you can do all these steps on your own or and
03:44And when you go on to the end file, you're gonna basically have the complete project when we're done building it
03:50All right, so I'm gonna save that so now that we have the plug-in inside
03:54We could start actually animating and the first step is we want to figure out what do we want to animate?
04:00Now that we have access to CSS properties
04:02All that's left for us to do is to define what do we actually want to animate and we've seen it already
04:07So let's just highlight that position. We're see that this is our background here. So I could literally just from my
04:14JavaScript edit from my counsel counsel from my inspector. Why am I talking like a
04:19Nerd. All right, so just find the element you want to animate. We know that elements
04:25I'm just gonna copy it really simple this way instead of going back and
04:28Searching through the HTML. It's so easy when you could just highlight select something
04:32Find what that is exactly and then copy what you need
04:36And I'm gonna go back into my editor
04:38And now that I have that element that I want to animate I could go ahead and just start my animation
04:44So I'm just gonna
04:46that like that and we're gonna go ahead and what we want to do is we want to create a
04:50tween light and
04:52From because we want to start from a specific position
04:55The next step is we want to provide what do we want to animate now?
04:59Just because I know I know that there's basically in this inner CSS
05:03There's the blue background if we find it right here
05:06We have our blue background and we have our orange background and really the only difference between the two is this one has a blue
05:13style CSS style
05:15Class and the orange has an orange one. So all I'm gonna do is I'm gonna just drop that blue making sure that both
05:22Rules will apply in other words. All three elements will be selected because this rule that I'm sending in is
05:31Appliable to all these three elements
05:33So now this new rule that I'm putting in that I'm applying and I could say hey to all the elements with this rule
05:38And by the way, that's exactly what it means basically
05:41It means that we're gonna animate ever more than one element so far in our last lesson
05:45We only saw how we animated one thing at a time at this stage. We were ready to animate more than one thing
05:50So this rule will actually based on whatever whatever fits to this rule
05:55It will animate all the things that apply to this rule
05:58so the next step is we want to say how long do we want our animation to be we want it to be one second and
06:04We're ready to say what we want to animate in our case. We want to animate the padding
06:10Top now deliberately I'm writing this because this is a very very wrong now
06:14If you know programming if you took our initial course
06:16You should know why it's wrong and if you do how about click on that pause button and right below?
06:21Why would this be wrong?
06:23and
06:24The answer to that is if you didn't pause the button you have one last chance to do that done chance is over
06:30So when you see when you see something like this basically what this means is padding minus top because this sign in
06:38JavaScript has a meaning it means minus so it cannot be used for variable names and because of that in JavaScript
06:44what we do is we camel case the variables of
06:47CSS and by the way in CSS there is no such rule so we could have a minus in CSS
06:52We have properties with minus between them and that's completely fine in JavaScript
06:57We're not allowed to and that's the reason why we create camel cases and most
07:00Third-party libraries that actually do these type of animations or do any
07:06Interaction with the DOM and the CSS will always have these camel case rules because that's kind of the workaround to be able to work
07:12with
07:13CSS
07:14now and
07:16Just a side note sometimes you'll see places where there it's not like that and then you wrap it in a string and
07:21Then it would be applicable
07:22But in this case in this library
07:24We send it over using a camel case and the next step that I'm gonna do is I'm gonna set the value that I want
07:30to change it to so how about we'll change it to be a hundred px in the beginning a hundred pixels are padding top and
07:36If we go ahead and just refresh this we should see that all three elements should start
07:40Animating if we did everything right and I guess we did it. Oh because I'm still in the start file
07:45so let me just grab that and
07:48File and there we go. You start that that was a little bit quick now
07:51Obviously, this is isn't perfect yet because we're not starting from the complete stop
07:56complete start
07:58So let's do that. And the second thing is that we probably want a slight delay
08:02So I'm gonna add yours delay of 0.5. Let me just break a line here. So it'll be easier for us to see everything here
08:12Alright, so we added our delay and we said the next thing that we want to do is we want to figure out
08:16What is the height of our element?
08:18So be able to do that what I'm gonna do is I'm gonna try to figure out basically
08:22What is the height of the full element?
08:24And if you look into the CSS I could see that there the elements are split down with an
08:30Li so I'm gonna approach that Li element and just ask it. What is its actual height?
08:36So to do that, I'm gonna I'm gonna use jQuery and I'm gonna just send inside
08:42The actual element. So I'm gonna go ahead and just find that element so I could just go ahead there and just type
08:48I could just go ahead and try this and just see if I get that value
08:53and if I'll do that and I
08:58Get that element. I'm gonna ask for the CSS attribute and then I could ask for the height itself
09:04Now I'm just gonna wrap this up in the console
09:08That log so we could actually see it and if I say this go back to my browser click
09:16Click on refresh and go to my console. We're gonna see that the value is
09:21144 pixels so we know that 100 wasn't right. So how about we go back into our code?
09:26And by the way again, we don't like putting hard-coded values
09:29I've talked about this a lot throughout the first chapter, but I'm gonna continue in saying that over and over
09:34The less hard-coded values you put in programming the better because what if you wanted to re-leverage this animation that you're creating for
09:41components that are bigger or if you have a small design change and you decide that it's gonna be 10 pixels bigger if you're
09:47Using hard-coded values
09:49It's gonna mean that you're gonna have to go back into your JavaScript and find that code to be able to update it and change
09:54So really what we want to do is we want to make sure that
09:57We're avoiding direct namings as much as we can whenever we can
10:02so going back into our code now that we know that we have access to our height we could definitely create a variable here and
10:09Assign it to it or we could just go ahead and just take that value and send it directly into our padding top
10:15And the reason is because we are not talking to this property anymore
10:19So this might look dirty to you
10:20You might not like how it looks like and if you don't then go ahead just create that
10:25Li height
10:27And you can just set there that value if we want to use the rules that we applied from our beginner course
10:33And I would apply here a n
10:36Li height
10:38Just to indicate to me that oopsie Li height just to indicate to me that this is a number but for me
10:44I would say that it's relatively intuitive because I'm literally saying I want the Li height
10:49So, you know that that's where you find your your
10:54Personal from preference in my case
10:56My personal preference is to try to make things the most literal that I can
11:00so if this is obvious to me that it's a number and even if in 10 years from now I look at this variable and
11:05I'll know that it's a number even without looking at the
11:10Application itself then I should say okay. This is fine. You know because a height is something that is a number
11:15Obviously in our case, it's not really a number because it's a pixel but you get my my point
11:19So it's a string
11:20But I don't really need to define it as a string because I know what it is and I know what I'm gonna use it
11:25For and I could recognize it very easily just by its name. That's personally my personal
11:32Favorite way of defining variables name names, but you do whatever you feel like is right and and do stick to whatever naming
11:40Convention that works for you. Alright, so let's give it a run
11:43And I'm just gonna put here a longer delay because I didn't really like that delay earlier
11:46and I'm gonna go ahead and click here refresh and by the way, I
11:51Like this, but I don't like the fact that they're going down at the same time. It feels really really
11:58unnatural so I might want to solve this problem and
12:02If I was working with tween max right now, I could have solved this problem using the stagger from function
12:09But I want to stay puristic with our tween light
12:12But you could as your kind of like a homework assignment
12:15Go ahead and grab figure it out on your own how to work with that tween max how to use the stagger from
12:22Just look it up in the API in the in the documentation and then go ahead and and solve it
12:28It's great practice to get used to working with this type of documentation
12:32I'm not gonna solve that now work because we're gonna progress into as we get by but what I'll show you is how
12:36Could we create animate all three in my case because I'm not using that more sophisticated library
12:42Component that by the way also as we know takes more file size. So if I went for that tween max
12:48That means I'm gonna be at 23k versus the 15k that I'm at so it's not a huge difference
12:54Not a huge difference at all. Once I'm using both the CSS and the tween light then the tween max seems to be
13:02More or less more or less not that far away
13:05So once we're using more than one plug-in, we're already ready to move on to that tween max
13:10All right. So let's continue what I want to do is I want to show you how could we break this apart now to break this
13:17Apart and create the animation separately because I'm not using the tween
13:21I'm not using tween max. What I'm gonna have to do is I'm gonna actually have to approach this element and turn it into a
13:28jQuery object and I'm gonna go ahead and do that and I just want to show you that if I just take this and
13:34I wrap it up and I'm just gonna go into my browser because I want to show this to you in our console
13:39And I'm gonna go right into that count console and what I want to do is I'm just gonna paste that value there
13:45And let's make sure that I'm not making a typo
13:48So I'm just gonna tape that value there and when we we set it back first of all
13:54Alright, cuz four is not a function. I was going for dollar all that work
13:58All right. So first of all, you'll see that automatically what we're having here is we have here an object that has a position of zero one
14:05two three
14:07Zero one two three. So if I go ahead and I do this and I this time around I just approach the first element
14:14Then I should get only that first element which is our first item
14:19so what I literally could do is I could basically approach my object create it and
14:25Just create it right up here before we actually start our animation and I'll just call this
14:31A
14:34Li
14:36Items, let's just call it items
14:37and if I just set this value as that value that's coming back here, then I could approach this element and
14:47Approach it one at a time. So I could literally just go ahead and say okay
14:50let's animate the first item by sending the first item in and
14:54I could set here that delay of one second and that's perfect
14:57And if I go ahead and just click your refresh
14:59We should see only see that first item animating now and that's exactly what's happening
15:04And I could literally just go ahead and do that for the other remaining two as well
15:08So if I just copy this and just do this three times in
15:16Total because we have their three elements
15:18So I could go to the walk to one
15:20I could go to the two and I could literally just play around with that delay that one will be one second one will be
15:25One dot one and one will be one dot two that way there's a little bit of a difference using the two and it's a little
15:31Bit more organic now what I want to give you as your homework as you're looking at this stuff
15:36You see how this feels on its own already
15:38It feels a lot more natural because it doesn't feel mechanic doesn't feel like they're all doing it in the exact same second
15:44So your homework and I want to give you a double homework if you choose to take it is one try to figure out
15:49How to do this with tween max just go to that library. I want you to use the stagger from instead of using this
15:55We're gonna learn about it later on in this course, but it's a good thing to just expose yourself to it
16:01Now the second task I want you to do is from the stuff
16:03We learned in chapter one about eases and we just saw our delays integrate it easy that you think works best
16:09Help me decide what ease should I put in our live site?
16:12And if you come up with a really cool ease that we love that we're gonna go ahead and switch our animation and use that
16:18Ease because we're gonna pry
16:20Integrate this animation once we're done with this chapter and put it into our website and the one that you create that is the best
16:27Little feature on our site
16:29Which means that you could add that to your resume and you could show that to people and say hey
16:34I added that on zero to geek comment. How awesome is that?
16:37so try to make the coolest thing you can and if we find if we think that it's really awesome and
16:43By the way
16:44If you're creating something then do use the tween line because we want to keep our file sizes in our site
16:48The smallest that we can so start from the basic what we're at with the skills that we developed so far and try to come
16:54Up with your interpretation by the end of this chapter when we'll be done creating this interactive sample, so
17:00Start thinking about that project, but don't complete it yet
17:03We're gonna complete it and complete it after you finish watching chapter
17:07Two all right so see you in the next lesson where in the next lesson
17:11We're gonna continue on and also move on to creating this rolled over and roll out effect and then animating
17:18Our element when the user rolls on and rolls off so see you in the next lesson when we do that
