CSS: Animations
Illustration by Bruce Heavin

CSS: Animations

with Val Head

Video: Animating an element into place

In this tutorial we're going to add a little bit of a personality to a basic social media nav listing by animating it into place with CSS. This is a fun way to draw attention to certain elements on the page as it loads, but it's definitely one of those things that's best in small doses. We'll also look at animating more than one property in our keyframes. We'll be creating a slight bounce-in animation for our social media nav. So when the page loads, it will look a little like this. Normally, something like this would be in site footer, but for simplicity's sake, I've left it as the only element on my page.
Expand all | Collapse all
  1. 4m 47s
    1. Welcome
      41s
    2. What you should know before watching this course
      58s
    3. Vendor prefixes and browser support
      2m 11s
    4. Using the exercise files
      57s
  2. 28m 16s
    1. Animation basics
      6m 32s
    2. Exploring animation delay and the fill-mode property
      6m 6s
    3. Working with animation direction
      4m 49s
    4. Understanding easing
      8m 47s
    5. Challenge: Adding keyframes to our animation
      49s
    6. Solution: Adding keyframes to our animation
      1m 13s
  3. 47m 37s
    1. Creating a seamlessly looping animation
      6m 27s
    2. Animating an element into place
      5m 43s
    3. Playing and pausing an animation on hover
      6m 20s
    4. Animating 3D transforms
      8m 6s
    5. Preparing a sprite image for animation
      4m 55s
    6. Animating the sprite image with steps
      5m 34s
    7. Chaining multiple animations on one element
      8m 2s
    8. Challenge: Adding a third animation to the chain
      46s
    9. Solution: Adding a third animation to the chain
      1m 44s
  4. 19m 54s
    1. A preview of what we'll be creating
      1m 10s
    2. Setting up the HTML structure
      1m 48s
    3. Adding the header animation
      5m 57s
    4. Animating the data
      6m 8s
    5. Adding interactivity with JavaScript
      4m 51s
  5. 12m 44s
    1. Why and when to use CSS animations
      4m 50s
    2. Organizing animation code for semantics and fallbacks
      4m 51s
    3. Crafting effective animations
      3m 3s
  6. 3m 0s
    1. Helpful online tools for creating and building animations
      3m 0s
  7. 34s
    1. Next steps
      34s

Start your free trial now, and begin learning software, business and creative skills—anytime, anywhere—with video instruction from recognized industry experts.

Start Your Free Trial Now
please wait ...
Watch the Online Video Course CSS: Animations
1h 56m Intermediate Feb 14, 2013

Viewers: in countries Watching now:

This course presents a short series of CSS animation techniques, such as looping, playing, and pausing, and puts them together in a small project: an animated infographic. Author Val Head also addresses using CSS preprocessors, adding transitions, handling vendor prefixes, and understanding the best uses for CSS animations. Plus, discover how to measure the performance and current level of browser support for CSS animations and how we can expect the technology to change.

Topics include:
  • Understanding delay and fill-mode
  • Dictating an animation's direction
  • Using easing
  • Adding keyframes
  • Looping an animation
  • Chaining multiple animations on one element
  • Setting up the HTML structure
  • Adding interactivity with JavaScript
Subject:
Web
Software:
CSS
Author:
Val Head

Animating an element into place

In this tutorial we're going to add a little bit of a personality to a basic social media nav listing by animating it into place with CSS. This is a fun way to draw attention to certain elements on the page as it loads, but it's definitely one of those things that's best in small doses. We'll also look at animating more than one property in our keyframes. We'll be creating a slight bounce-in animation for our social media nav. So when the page loads, it will look a little like this. Normally, something like this would be in site footer, but for simplicity's sake, I've left it as the only element on my page.

Let's go into Coda and look at the HTML behind this example. The HTML behind this nav is pretty typical nav material. It's a list of links to Flickr, Dribbble, Twitter, and Facebook. If we switched to our CSS, our starter CSS is a bit more complex and usual due to the specific background positioning for each logo image in our nav. Not to worry, though, all the steps adding our animation are still the same despite all these extra starting styles. I've decided that I'd like to have my social-nav bounce into place. So, I'll need to create keyframes that first have it placed out of sight above the page and then I'll have to move it past its normal position at first so it kind of overcompensates and then move it into its originally intended position.

I'm going to need to do this with three keyframes. So, let's start writing our @-keyframes block. I'm going to call this animation bounce-in since that's the effect that we're going for. I'll just add a bit more space so we can see what we're doing. I'll be defining my keyframes in percentages since I know I'll need at least three. So, I'll start it with my 0% keyframe, and in this keyframe I know I want my animation to start with my navigation above the page essentially out of sight, higher up than we can see in the browser.

So we'll set a translation--a translation along the Y axis of -200 pixels. So that should move us up and out of view. And then to create the balance when my animation is almost complete, I want it to move past its original position just a little bit lower than it should be. So I'm going to guess that might be around 90% since that's mostly complete, and I will add a translation here of 8 pixels, so this should be just a little bit lower than it really should be.

And then at 100%, my last keyframe of the animation, I'll add another translate of 0 which will have our navigation end up in exactly the same place as it would have originally with a translation of nothing, of zero. We want to have the entire navigation move with this animation so we'll need to assign the animation to the unordered list that's containing our entire nav. That's up here in our unordered list with the class of social, so I'll add the animation properties here. We'll add our animation.

We'll add the animation name of bounce-in since that's the one that we just defined keyframes for. We'll set our duration to 1 second so it's fairly short, nothing super long in this case. I'm going to set my animation timing function to linear, and I'm going to have this animation iteration count set at 1, so it will only play one time. The direction will be normal and my animation fill mode will be backwards. And the reason I'm going to add backwards in there is so my navigation will stay out of sight at the beginning in case there's any delay in the animation being applied. I'm also setting my timing function to linear to let the spacing of my keyframes implied the ease-in of our little bounce.

That's easier for me than trying to find just the right ease-in to create the bounce. It's just one tiny little bounce, so it's pretty easy to do with the keyframe that we've defined. So now we can save our CSS and go preview what our navigation looks like in the browser. So if we refresh, our nav starts out of sight, falls in, gets a little bit too far, and then bounces back into place. So that's pretty much the effect we are going for. But there's one other thing I'd like to add. Having an element fade in while it animates into place is a pretty nice touch. So let's go and add that to our animation as well.

So we'll go back to our CSS and scroll back down to our keyframes, and I'm going to add an additional property to a couple of our keyframes. I want to have the nav start out as completely transparent or with its opacity set to 0. So let's add that in to our 0% keyframe. Let's make a little space and then add opacity of 0. So, when our 0% keyframe while our nav placed above the page it will also have opacity of 0. Obviously, we're going to need to set this to something you can actually see.

So, we'll also add this opacity property to our 90% keyframe. Make a little space here, and then set the opacity at the 90% keyframe to 1 which is completely opaque or actually 100% visible. So, now our navigation will be fading in while it drops into that initial bottom position. At our 90% keyframe, our opacity is set to 1, which means our navigation is completely visible, and we don't need to list opacity again in our 100% keyframe because we don't want it to change any further during the animation. We want it to stay at 1.

If we don't list the property again in future keyframes to overwrite the last value, it will continue at the last value we set for the remainder of the animation. CSS treats animations of multiple properties in the same set of keyframes as nearly independent. They're part of the same keyframes but they don't all have to change at the exact same time, that's pretty handy. Let's save our CSS and go back and preview our navigation one more time. So, we'll refresh the page. Now, that we've got an effect we like, let's head back to our CSS and add the rest of our vendor prefixes so this will work in browsers that aren't just WebKit.

Great, so now we have all our vendor prefixes in, and we're all set to preview this in any browser we want. We've got a nice little effect going on our social-nav now while the page loads, and we've started developing slightly more complex animations with multiple animated properties within one set of keyframes.

There are currently no FAQs about CSS: Animations.

 
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

* Estimated file size

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed CSS: Animations.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferences from the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

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.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.