Using an Animation library
So far we created all our animations on our own without the help of any external library. Although we used jQuery we ignored the fact that jQuery has a few very helpful animation methods within. In this lecture we will learn the foundations of good animation and see it in action using the jQuery library animations.
Keynotes:
- Moving to animation libraries.
- The fundamentals of good animations.
- Fading in our document.
Video Transcript
00:00As your animations get more complicated,
00:03it bestows upon you to use
00:05an animation library because you don't want to
00:08need to add hundreds of lines of code to create animations.
00:11Beyond that, there's a lot of
00:13advantages of working with these libraries,
00:15and that's the main topic of this last lecture in this title.
00:19We're going to move to working with
00:21the jQuery animation capabilities
00:23in its built-in library possibilities.
00:27We're also going to talk about
00:28the foundations and the fundamentals of good animation.
00:32We'll wrap up by actually creating
00:34a fade-in to our whole document.
00:36Let's jump right into it and let's use and create
00:39animations with a library that
00:40already has animations built into it.
00:43A great design is nothing without a great animation.
00:48I really mean it, and especially in this modern day,
00:50where every site has a great design or a lot of them.
00:53It goes down to how clean and how simple your animations are.
00:57This last lecture in this title and
00:59section is all about animations.
01:01Now, we're not going to continue building up
01:04our own library like we've done so far,
01:08because it's going to take a lot of hours to
01:10build a really great library.
01:12Instead of that, we're going to leverage the fact that we're
01:14working with jQuery to see how to create really cool effects.
01:18I'm going to go ahead and what I want to do is I want to
01:20create a fade-in effects so our content will reveal itself,
01:23something that was very popular with
01:25Apple when they do some cool stuff on their site,
01:28where they whitewash everything and then fade it in.
01:31In our case, we're going to use our current structure,
01:34our current colors and manipulate them and
01:36fade them in and make it really cool.
01:38Let's get started. It's really simple.
01:40What I'm going to do is I'm going to go ahead and
01:42just approach our jQuery and wrap it around in our whole body.
01:47I want to fade in the whole complete body in.
01:50I'm going to go ahead and just add here a hide,
01:53and hide it and set it to be zero.
01:55If I do that and I go back into my application and click on refresh,
01:58you'll see that basically everything will disappear,
02:01which is a great start for us.
02:03The next step for us once everything was disappeared,
02:06I'm going to go ahead and add your slight delay,
02:08let's say of about 400 milliseconds,
02:10and then fade in animation at all in,
02:13and say I want it to take about 2,000 milliseconds or two seconds.
02:18If I go ahead and save this and click here on refresh,
02:20that's all I really had to do to start
02:22creating something here that will be really interesting.
02:25Now, this on its own is not interesting enough.
02:28I want to show you how you could basically
02:30transition all these items together.
02:32What I want is to have all these items take
02:35basically step-by-step transition themselves in.
02:38By the way, I deleted our cute text animation,
02:41just so we have your clean fresh start,
02:43and we're going to add it in once we're done adding our animation.
02:46Because right now, if I put it right inside there just as it was previously,
02:51it's just going to be quite confusing.
02:53It's going to look really weird in our animation,
02:55so don't worry if it's that it's not there.
02:58For now, let's ignore it for a second because we want to
03:00add it in only after we're done with all of our animations.
03:03The next thing that I want to do,
03:05I'm just going to duplicate this animation.
03:07What I'm going to do is I want to animate now phasing in,
03:11going through let's say our article.
03:13I'm going to go ahead here and instead of approaching our body,
03:16I'm going to approach our article,
03:18and I'm going to hide it as well.
03:19But this time, I'm going to add a delay
03:20of about a second and a half,
03:23making sure that it's coming in a lot after our basic body.
03:27If I go ahead here and click here on refresh,
03:29we're going to see that it's starting to get more interesting, our animation.
03:33There's this wave happening inside of here.
03:36I want to continue creating this wave,
03:38so I'm going to go ahead and also duplicate this and
03:40find maybe the actual Canvas wrapper itself.
03:44Let's go ahead and add that Canvas wrapper as our third item,
03:48and the more of these you create and the more you layer them up,
03:52changing the delay really,
03:54that's where your key is because you're basically transitioning item by item,
03:58item by item in, you'll create a really cool effect here.
04:02So if I go ahead here and click here on refresh,
04:04the more of those you do,
04:05the more it's going to be interesting.
04:06It's almost like it's breathing.
04:08Now, there's a few things that I really wouldn't want happening,
04:10such as this animating or our item coming in.
04:13But let's do it step by step,
04:15and the next step for us is what I really want to do or what I need to do,
04:18is I want to create here some set interval or set timeout more accurately,
04:23and I'm going to put inside of here an anonymous function.
04:26This anonymous function, all it really will do is just trigger
04:30our queued items and just add them into our queue.
04:34So I'm going to go ahead here and just add those items into the queue.
04:38Once these items are inside of this queue,
04:40I also want to set out when will this happen roughly after four seconds,
04:474.3 seconds roughly.
04:49Now, what's going to happen is,
04:51and let's ignore the canvas for a second,
04:53but also the canvas probably needs to be optimized,
04:56as in this case is where we're going to have the fade-in happening,
04:59and then these items are going to come in.
05:01Now, we still probably want to also make sure that this animation is not happening.
05:05So let's go ahead and also just grab everything that relates to our canvas,
05:09which is basically everything until this line,
05:11and I'm just going to cut this out,
05:13delete it from our init function,
05:15and I'm going to go ahead right after our init function,
05:18or even before our update canvas,
05:21and I'm going to call this init canvas.
05:24Let's go ahead here.
05:25I'm going to just paste everything inside of our init canvas.
05:28All that's left for me to do is also figure out where to call this init canvas.
05:33If I go ahead here and let me just check if there's any scope issue,
05:37anything that I might know,
05:38everything here seems to be completely self-contained.
05:42So I could go ahead here and just add another interval,
05:44and I'm going to go ahead here and just set a new interval,
05:48a new timeout, excuse me, not interval,
05:50set timeout, and I'm going to call our init canvas,
05:54and for our end canvas,
05:55I'm going to roughly, because I don't care if it's happening in parallel,
05:58I'm going to init our canvas maybe around after six seconds,
06:02and let me go ahead and save this.
06:03Now, I'm not going to go ahead and make it perfect
06:05because I'm going to leave that to you.
06:07The most critical part here and the most important part
06:10is that you transition these steps and figure out
06:13the right constructs here.
06:15For example, and for our canvas,
06:17we might want to fade in the canvas as well.
06:19But your goal really is to go ahead and make it as smooth as humanly possible.
06:24The smoother and less jumpiness,
06:26and there's definitely jumps here,
06:27so it's not perfect and we're going to leave it to you to make it perfect.
06:30But the more perfect you make it,
06:32the more exciting it will be for users and the more
06:34beautiful and more engaging your design will be.
06:36So it's not about adding a lot of animations,
06:39it's about making sure that your animations together
06:41holistically feel completely natural.
06:43Just like we did with our gradients back long ago in the beginning of this course,
06:49where I told you try to make your transitions very gentle.
06:53Don't make big sharp color changes because
06:55big sharp color changes just don't work well.
06:58Same is true with animations.
06:59The smoother, the more simple they are, the better they look.
07:03So I hope you enjoyed this title and I hope you
07:05enjoyed this animation section, our JavaScript animation section.
07:09Don't forget to check the references below
07:11because I strongly encourage you if you're going to
07:13create really complicated animations,
07:15make sure to check out GSAP,
07:17which is an animation library in
07:19JavaScript that was designed and intended purely for animation.
07:23Contrary to jQuery, which also has animation,
07:26GSAP is a beautiful library that has an amazing capability
07:30way beyond anything we covered so far.
07:32I just want to say in one word, for example,
07:34if you want to pause an animation or change an animation midway,
07:38you can do that with jQuery or it would be really complicated.
07:42Contrary to that, you could definitely do that with
07:44a third-party library such as GSAP,
07:47which you'll find in your references in
07:49the source files below inside of your HTML file.
07:52So that's it, we are completely done.
07:55In this lecture, we saw how to take advantage of the fact that
07:58jQuery has a built-in animation library.
08:01With that said, there are better libraries for animation,
08:04much better ones which you'll find in
08:06your references in your source files,
08:09such as GreenSocks GSAP.
08:12Now, we talked about it briefly throughout this course,
08:15and I think we're just about done,
08:17and I really, really thank you for taking this course.
08:20I hope you really had a great time,
08:21and I hope to see you in
08:22a future title of mine with packed publishing.
