Start learning with our library of video tutorials taught by experts. Get started
Viewers: in countries Watching now:
With robust and ever-increasing browser support, it is now possible to take advantage of expressive CSS3 capabilities across modern browsers. In this course, Joseph Lowery explores the possibilities of the new coding options, which animate well over 50 different properties automatically or interactively, and how they open the door to enhanced user experiences. This course covers the range from simple to complex transitions, including 2D and 3D transforms, and illustrates how transitions are expedited in various web authoring tools, as well as Dreamweaver. The course also contains a start-to-finish interactive slideshow project that allows you to practice and see the transitions and transforms immediately in action.
That's fine for what it is, but let's bring it into the code editor and see how to breathe a little life into it. Now rather than rotate the logo like the hands of a clock, I would like the logo to spin like a weather vane. And that will require the RotateY function, which is 3D transform. To set that up, I will need to establish a perspective in the containing element, which happens to be in this case, outerWrapper. So we'll go to our outerWrapper rule here and add in -webkit-perspective and set that to a medium value 500px.
Now I am going to copy and paste my webkit perspective line, as we've done before. I will do it three times here, one for Mozilla, one for Opera, and one for the CSS3 Property perspective. All right, let's clean up that extra empty space there. And now let's define the transition in the logo rule. I am going to use the keyword all to cover any properties I need to control.
So -webkit-transition: all, and let's make this last a little bit. Let's bring it up to 2 seconds, and we will use the ease-timing function. Okay, so again, we will do a little copying and pasting, save some time, replace -webkit with -moz for Mozilla, and then we will take care of Opera and we'll get rid of -webkit altogether, so we just have transition.
Now we are going to need to add the transform to a hover state. Put in the basic selector logo and add hover. And let's set up our transforms, -webkit-transform, and as I said, we want this to rotate around the Y axis. So I will go rotateY, and let's have it go all the way around, so 360 degrees, or (360 deg).
Add in a semicolon, and we will copy that line, paste it three times, and do our little copy-paste dance. Okay, let's save it, and we will test the page. I will go over to Safari now, reload the page, and when I hover over the logo, it should spin. Okay, so there's my spinning logo, and when I hover out it reverses, just as you might expect. Well, the rotation is cool, but how can I be sure someone is going to hover over the logo? It would be much better to have it rotate automatically when the page loads.
And then I move my cursor past that opening and closing parenth, and enter it in a curly brace. I will hit Return once just to make a little space there. And let me go ahead and close off this function here with a semicolon before I add in the code that's to be executed, which in this case is going to be adding a class to the selector of ID logo or hash tag logo. So in jQuery we start off with a dollar sign and then opening and closing parenths, and within that, quotes.
And now add in our selector, which in this case is #logo. And then after the parenths we put a dot and add in the function, addClass, and again, open and closing parenth and quotes, and the class we are going to add is called animated. All right, let's put a semicolon after that. Now let's go down to the hover rule, and the first thing I am going to do is just copy it, because we are going to be able to reuse it.
I don't want to lose this in case I want to go back to it. So I will copy it, and now I am going to comment it out by putting a /* above it, and a */ below it, creating a new line, and then pasting it back in. Now we are going to change the selector from #logo:hover to .animated, and while we are at, why don't we beef it up a bit? Instead of just doing one rotation, let's do two, and let's have it spin the opposite way.
So to do all of that, all I need to do is to change the 360 degrees to a -720. All right, we will do that three times more. And since we beefed that up, why don't we beef up the transition as well? Since we have two rotations, let's make it go 3 seconds instead of 2, and let's go for a custom timing function. Instead of ease, let's use cubic-Bezier to create one that starts out really slow, and then just takes off.
So we replace ease with cubic-Bezier, and open and closing parenth, and in that four number values (0.950, 0.050,) that's the first of two X/Y coordinate pairs. So let's enter the second ones now, 0.795, and finally 0.035.
Okay, let's copy our changes and then replace the existing code with the new super-duper code. Finally, let's add a brief delay so that the animation doesn't start immediately after the page load, but waits just 1 second. So in the Logo rule, we will add in our transition-delay property starting with the webkit version. And there it is, the code hints. So let's take advantage of that, and we will make this 1s for 1 second.
And now let's do our other versions by copying and pasting that in several times and then changing the prefixes where we need to. All right, great! Let's save the page, head back over to Safari. I'm going to refresh the page, and let's see what happens. Excellent, looks pretty sweet! We have got a nice delay there and then the logo just goes crazy, but in a very precise, controlled way. CSS transitions and transforms like this 3D rotation work really well for bringing simple eye-catching animations to banners and other ads.
There are currently no FAQs about CSS: Transitions and Transforms.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.