Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Animating icons

From: Deploying Icon Fonts for the Web

Video: Animating icons

In this exercise, I want to take a look And then you have to name your animation, whatever you want to call it.

Animating icons

In this exercise, I want to take a look at extending the styling of our icon fonts past just sort of basic visual styling into something a little bit more complex, like animating it through CSS. A lot of icon sets have icons that are designed to animate. Most notably, loader icons like the one you are seeing here at the bottom of the page. So what we're going to do is we're going to animate our loader icon by making it spin. And thus, simulate the loading of a page or element. Or widget or something like that. Now, I want to point out that as we are going through and styling this, I want you to notice that CSS animation support is pretty good right now.

However, you do have to work hard sometime to make sure that it works correctly across multiple browsers. Okay so here we are in the same file within the code editor. This the animate.htm. I want to scroll down and show you guys kind of how the icon is being displayed. It's right there in the paragraph. And we're not doing anything different from the way we normally display our icons, so we're still using data icon attribute, we're still using aria hidden. I've got some alt text there that of course we're hiding for accessibilities sake.

So really we don't need to make any changes as far as our deployment strategy goes. Okay I'm going to switch over to my CSS and I'm going to scroll all the way down to the bottom where we have our icon font styles. Again so this is just sort of our global icon style. The first thing that I want to do anytime that I'm doing animation Is I have to set the animation up before hand. And we do that using an at key frames rule. So I'm going to type in at key frames. And then you have to name your animation, whatever you want to call it.

And I think naming it loading makes a little bit of sense, since that is what we're simulating. And then inside of that, there are a couple of different ways this syntax works. Essentially You just basically say, hey, it looks this way at this state, and then this way at this state. And you can have as many states in there as you want, so you can create steps for your animation, or key frames, if you will. So it's a pretty cool way of working. I'm just going to go from 0% of the animation done, and then inside of that. And I always like sort of typing in the opening and closing curling braces to start, because when you start nesting them like that it's really easy to get lost.

Okay so I'm going to do a transform here and I'm going to transform this by rotating it. And I'm going to rotate it zero. Meaning it looks exactly the way it did when it started. So when it's at zero It's essentially at the start position. Now again, I love copying and pasting. So I'm going to copy this. Paste it. And this one is going to be 100% of the animation, and that's the animation being finished. So it's going from zero, start. To 100% finished and if we wanted to we could have multiple sets here, you have zero, 50, 100, anyway that we wanted to do this.

Okay, so since we wanted to spend all the way around we're going to give it a 360 degree rotation and for that transform value We do 360 and then DEG for degrees. All right now. Let me save this. Now at this point, animating it should be pretty easy. All I've go to do, is go down into the element that's controlling my icon and call the animation. So I'm going to go right down after line height and I'm going to type in animation. And the name of this animation is loading. Remember, we named it right up top.

So I'm pulling the name from there. Then we have to say how long we want the animation to take. And I want it to complete its rotation in one second, which will be pretty fast. How many times do I want it to rotate? I want it to rotate an infinite number of times. I don't want it to stop. So you can say, you know, we want it to rotate twice, or three times. In this case I'm going to say infinite. And then we have to tell it what kind of timing we want for the animation. TIming is basically things like easing. For easing you can have things accelerate at the beginning and slow down at the end. Slow down at first and then accelerate towards the end.

I just want linear because I want one nice constant speed the whole way through. Now if I save this, I go into one of my browsers and refresh it, I get absolutely zilch, nothing. Well, we've gotta remember what type of element we're inside of. Right now, we're in a span, which is in-line element. And animation is not going to work on in-line element, so I'm going to type in display. Inline_block. Save that.

Preview it, okay great. Now it's, it's spinning that's exactly what I wanted. So one of the things we have to remember is that if you do have an in line element, and icons are typically inline depending upon where you're using em. You at least have to make it into an inline block element in order to actually transform it, so that has everything to do with the properties that you're actually trying to animate, in this case, we're trying to animate the transform property. Okay, now you may have noticed that I was testing that in Firefox and throughout this entire course I've been testing it in Chrome, right? So what happens if I go over to Chrome, with the same page, and test it? Absolutely nothing.

And the reason for that, is the animation syntax has not been unprefixed yet. What does that mean? It means that a lot of browsers support animation, but they only support it through vendor prefixes. And Web Kit is certainly one of those. So, what I'm going to do, is I'm going to take my animation right here, I'm going to copy that. And then I'm going to paste a copy of it before that. We now have to add another version of our animation, this targeted specifically to WebKit. We do that by saying at _ webkit-keyframes.

So we've gotta change that. Then we have to remember that the transform property is also prefixed inside WebKit browsers. So now I have to prefix that and I have to do that twice, which makes me unhappy. There we go, we'll save that. And then finally, we're not quite done yet. I still go down and I have to call the animation again. So I'm going to copy this Paste it. Then I have to prefix that with webkit-animation. I'm going to go ahead and save that now, because I know this will do your heart a world of good.

There are also prefixes for Opera, there are prefixes for Mozilla for older versions of Firefox, and I think there are prefixes for IE. I'm pretty sure there are. All right. So I'm going to save that, go back out to Chrome, refresh and now I have my animated icon. So although animation can add a lot of visual punch to our using icon fonts, one of the things you want to be very careful with it is to make sure that you're testing it across multiple browsers and that you're really familiar with the syntax, so that you'll know when vendor prefixes are required.

And when to provide a fallback in case animation is not supported.

Show transcript

This video is part of

Image for Deploying Icon Fonts for the Web
Deploying Icon Fonts for the Web

21 video lessons · 1818 viewers

James Williamson
Author

 

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
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.

Join now "Already a member? Log in

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 Deploying Icon Fonts for the Web.

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?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

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 preferencesfrom 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.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

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.