Moving into the 3D realm
Beyond animations the GSAP Library is a fantastic library to manage timing in general. In this lesson we're going to leverage TweenLite.delayedCall to delay function calls. Our animation is lackluster currently (very flat), when we use the rotationY property on its own. To solve this problem, we will create a transformed perspective that will take our element from its 2D flat environment and output it in a 3D perspective.
Video Transcript
00:003D, just like me, and that means we're ready to look into a couple of 3D transformations.
00:07Don't worry, they're really not complicated, especially when you're using with a wrapper
00:10animation library like TweenMax.
00:14Let's just jump right in and see what it is.
00:16Really what we're doing is adding a little bit of perspective into our 2D animations
00:21to give them a little bit more depth.
00:23So they're not animating in a flat area, but with supposedly a camera or a distortion
00:29that enables us to create a little bit more personality to those animations.
00:33So let's look into that and see how we do that as we flip our cards in an attempt to basically
00:39create a switch of content, which is something common where you want to update the content
00:44but you want to do it in a creative way.
00:46So that's what we're going to do.
00:50Next is I want to play around just a little bit with CSS3.
00:55Now this completely depends on your browser's compatibility and depends when you're doing
01:00this and it depends, the quality also depends on the browser itself because the animation
01:06library itself, Tween, Lite, TweenMax, and so on and so forth, don't actually create
01:11the animations.
01:12They're manipulating those CSS properties.
01:15So it really just depends how your browser renders those attributes.
01:21So that warning, let's get started.
01:24Let's see a little bit of playing around with our transformation.
01:29What I want to do is I want to create basically a time stamp that every certain amount of
01:34time that we'll have a flip, we'll start with just making a flip that happens once.
01:38So how about after 30 seconds, we create a flip and supposedly change our content.
01:44We won't really change the content, but we'll pretend we are.
01:48So I'm going to go ahead here and what I want to do is I first want to create that
01:51delayed call.
01:52We're going to learn how to do that.
01:55So I'm going to go ahead in our on ready function and just do right on the bottom after we're
01:59done with everything.
02:00I'm going to add a new Tween Lite function, but this time I'm going to call the function
02:04delayed call.
02:06Now the delayed call with uppercase C accepts a couple of parameters and you're encouraged
02:13to check the documentation because there's more parameters than what we're going to look
02:16at right now.
02:17I'll put as the first parameter for seconds because I want to start with our testing immediately.
02:22And then I'm going to call a specific function.
02:24So in this case, I want to call the function flip news, not flip them, flip new for moves.
02:33Let's try it one more time.
02:34Flip news.
02:35So I'm going to call the function flip news four seconds in and let's go ahead and just
02:40create this function flip news.
02:45And what we what do we want to do in our flip news function?
02:49So first of all, after four seconds, what I really want to do is I want to approach.
02:54I want to I'm going to need that element here because really what I want to do is I want
02:58to rotate all those elements.
03:01And I'm going to go ahead and start with just doing a 3D transformation by going
03:06ahead and just calling that Tween Lite.
03:08I'm going to animate it to going to take my elements and let it animate for one second.
03:14And I'm going to go ahead and just literally animate our rotation.
03:20Why?
03:22And I'm just going to say, hey, I want to rotate you by one hundred and eighty degrees
03:25just so we could look at it for a second before we do anything else.
03:29Now just by doing this, if I go back into my browser and click on refresh, we're already
03:33going to get like this nice transformation, which is lovely.
03:37So we'll see that in a second and we'll see how this we got this beautiful little
03:41flip.
03:42Although it's very fast, what I'm going to do, I'm going to slow it down and make our
03:45animation a little bit less pretty.
03:48We're going to see that our animation doesn't have a lot of perspective.
03:51We're basically very flat and we want to give our animation not necessarily real 3D,
03:57but we want to give it a little bit of depth.
04:00And you can see that right now, this on our line here, we're staying in this kind
04:04of like bound in this 2D space where we're flipping our element.
04:07There is no perspective.
04:09And realistically, that could never happen in a real 3D scenario.
04:14You would always see that it's getting a little bit larger or smaller.
04:16You would get a little bit of a distortion going on.
04:19So to make that happen, we're going to change the perspective of our element.
04:27Now to change the perspective of our element, there's a few ways we could do it.
04:31One, we could set it specifically for each item by basically setting.
04:37And we want to do this before we start our animation.
04:39So we would basically create here, basically a tween light, and we would have here a set.
04:45And then we would set our properties of our LI and then define them.
04:50But what I want to do is I want to create a default value and the way, oh, let's just
04:56do it this way.
04:57And then we'll see also the default value.
04:58So first of all, I'm going to set the element itself.
05:00So in our case, I want to set multiple elements at the same time.
05:04The next step is I'm going to actually set the actual property.
05:08And to set the property, what I'm going to do is, and this is a explicitly tween light
05:14property, although it's masking behind the actual CSS property, which is the transform
05:19perspective, which I'll just copy that because it's a long word, transform perspective.
05:25And then I could set here a value.
05:26So I'm going to start with a value that is really small.
05:28So we'll be able to see what that actually is.
05:31Now the transform perspective or our perspective is how far are we from the object and how
05:37far we are from the object is going to affect how big the distortion is.
05:42So if I go ahead here and I just click on refresh, we'll see that 10 is really close.
05:46So we're going to get this in our face animation almost.
05:49And we'll see how it's not almost in our face as it's animating because we're really
05:53close and crazy close.
05:56Now the more that our, the more that we go further out away, the further away our animation
06:03is from us or the less detailed you could say the transformation is so we have more
06:08subtle animations.
06:10Now the subtleness, the closer, the larger the number is will become even more subtle.
06:15So in this case, if I go ahead and just go for a really, really large number like 2000
06:20will still have a distortion, but it's going to be a very minute distortion that
06:25is not as noticeable and you can see that we still have a distortion, but it's a very
06:29small distortion and notice also that we're, as I'm working in Firefox, you can see as
06:34this number is really big.
06:36We also see a very big pixelation as we're animating and that pixelation isn't as as
06:42bad when we're going for lower numbers.
06:44So you really want to find that sweet spot and this is something you're going to have
06:48to test in different browsers and it's something that's going to change with the browsers
06:51as they become more, you know, newer and better.
06:54And in this scenario, we still have those pixels, but they don't feel as bad.
06:59Although unfortunately with 3D, I personally don't do too much 3D mainly because of those
07:04issues because I really don't like those pixelations and you tend to see them in 3D
07:09effects more than you do in 2D effects.
07:11And a lot of it has to do also with our background.
07:14So our background is making it a lot more sharp.
07:16If our background was darker, it wouldn't be as noticeable.
07:20All right, so that's our transformation.
07:23We're going to play around with this transformation.
07:25But what I want to do next is we want to catch our element as it's halfway through.
07:29But really what we wanted to do is we want to animate only 90 degrees and then flip
07:34or change our content and then go another 90 degrees.
07:38But when I do this 90 degrees, we're going to see that we have a small slight issue.
07:42And our issue is that when we're animating out at notice, as it collapses, our animation
07:47gets slower and that's not what we want.
07:51We want our animation to have this constant speed, especially at this stage.
07:56So what I want to do is I want to create basically no ease on our element.
08:00And to do that, I'm just going to add another property for our ease and I'm going to go
08:04ahead and just add here ease, but I'm going to put the value of linear.
08:08And instead of instead of ease in or ease out, I'm just going to say ease none.
08:13I don't want any eases.
08:15And by setting this to ease none, when we go back and refresh, we're going to see that
08:20now when we're doing that flip, it's not going to be procrastinating towards the end.
08:25It's just going to go ahead in the same speed from beginning to end.
08:30Perfect.
08:31So now that we have it in the same speed that we want it from beginning to end, what
08:34I want to do is I want to basically listen to when it's done.
08:39And to do that, I'm going to add another callback, which will be called on complete.
08:45And on complete, we're going to call that actual change, change news content.
08:51And we could create that function really quickly, change news content.
08:57And just for the sake of not having an incredibly long lesson, let's break this video down.
09:04I encourage you to play around and change the content and actually finish the cycle yourself
09:09because in the next lesson, that's exactly what we're going to do.
09:11We'll change the content, just fakely, just put some content inside and then continue our
09:17flip.
