Creating 2D animations
I'd like to dedicate a little bit of time to talk about 2D animations. The most common type of animation you'll be doing on a daily basis. In this lesson we're going to create a few 2d animations and explore 2D transformations.
Video Transcript
00:00No conversation about CSS would be complete without talking about the 2D or CSS 2 type of animations
00:07and the 3D slash CSS 3 animations. Although we were not going to cover everything, this lesson is going to be short,
00:14dedicated to a few things we already looked a little bit into which are going to be the CSS 2 type of animations and the next few
00:20lessons after that are going to go into that 3D domain where we'll explore a few different cool little animations.
00:26So let's start with that 2D stuff.
00:30So for the sake of our practice, I just want to get all of our elements to basically animate into their position.
00:35And really what I want to dedicate this lesson is a really quick lesson, a very to the point lesson.
00:41We're talking about CSS 2 properties which we've played around with.
00:45And all these stuff you can just approach directly with your Twinlight library.
00:50And I wanted to kind of separate this talk with our next lesson which will be about the 3D properties and the CSS 3 properties in general.
00:57So I'm just going to create an animation that I'm not necessarily a fan of.
01:01But let's go ahead and create it just for the sake of that.
01:05And I already started typing that so let's just start ahead and do it all over.
01:09So I want to go to the Twinlight 2 and I want to animate all these three items that come from here.
01:15I want to animate the properties of skewX.
01:21And by the way, you can find most of the properties directly in your CSS documentation.
01:28And some you can find in the jQuery documentation.
01:31Now let's just type in your minus 10 degrees.
01:33Now by default, if you just put your minus 10, Twinlight will append into the degrees.
01:39But it's a good practice to use that terminology and be explicit because you could also use radians.
01:45Radians and a lot of these different properties.
01:47So the more explicit you are like we're working with PX for pixels because some points sometimes it's a different measurement count such as points.
01:55And I'm just going to skew it and I'm going to push my elements to the left starting from that 200 pixel point.
02:01So if I save this and go back into my browser and just click on refresh, we'll see that our item should start from that.
02:07Oh, I did a from by mistake.
02:09And what I really wanted to do was I did a to by mistake and I wanted to do a from.
02:14So if I just go ahead and do the fix that really quickly, breaking a line.
02:19So it's easier for us to see what's going on here and go ahead and click on refresh.
02:26And there we go. So this is basically the effect that I wanted to have.
02:31And probably I'd want to make it a little bit faster.
02:34So I could go ahead and just bump up that speed a little bit.
02:38Maybe we'll put it at zero dot six.
02:40And before we wrap this up again, just a reminder right now, this is not efficient because we're recalling the same elements over and over.
02:47So in this case, if I know that I'm going to be approaching so many times the L I, then it's probably a good idea to just go up to the top,
02:54create an L I variable, define it in jQuery, and then just save it right there and then reuse that variable throughout our calls,
03:03because we don't want to call a function every time we want to approach it if we're approaching it so many times.
03:09And then I would just go ahead here and update all these different elements where it's being called.
03:14And by sending a jQuery item directly to our tween light, it doesn't need to find it in the DOM.
03:20It could basically approach it and use it the way it is.
03:23So I don't have to I'm cutting down the amount of processing just by doing this.
03:27And it's a big effect, these type of stuff.
03:29So if I say this, go back to the browser, shouldn't see any big effect, any big difference, everything should be working the same.
03:35It's coming in a lot smoother.
03:37Now you can play around with a lot of CSS attributes.
03:40I encourage you to do that.
03:41We're not going to go through every single CSS attribute.
03:44This is it about CSS in general.
03:47In the next lesson, I'm going to want to talk to you a little bit about the CSS3 attributes.
03:52And what I'm going to do or what I want to do with you is kind of create a fictitious switcheroo here,
03:58where maybe this will animate out and come in with different content.
04:03So maybe we'll flip over and when it comes, it will come back as different content, assuming that we have different content.
04:09So we're not really going to switch the content.
04:11We're just going to do that flip, assuming that there is that type of scenario.
04:16And maybe we'll add also a timer to make sure that maybe once every 30 seconds,
04:20it will do that unless the user is in a rollover state.
04:24All right, so let's continue in the next lesson.
