Placed in: Home arrow Programming arrow CSS arrow CSS3 quickie: The Facebook loading animation
CSS3 quickie: The Facebook loading animation

After the couple of jQuery Quickies that have been placed online on this website, I today present you a CSS3 quickie. Just a short walkthrough to create a simple effect, to learn some basic stuff. In this case, we're recreating the Facebook loading animation using CSS3 animations. I'm pretty sure that you've seen the animation before, if you're a Facebook user.

Facebook loading animation

We're using CSS3 keyframes to create the desired effect. We'll be using prefix free from @LeaVerou to use unprefixed CSS3 properties.

Demo Facebook loading animation   Download Facebook loading animation

Take note this example only works properly in browser that support the keyframes property. I've tested this script and verified that it's working in the latest versions of Firefox, Chrome and Safari.

The source

The source code for this animation is actually pretty simple. I've added comments to make things clear.

HTML

 
<!-- Facebook Loader -->
<div class="loader">
    <div class="bar"></div>
    <div class="bar"></div>
    <div class="bar"></div>
</div>
 
/* FACEBOOK LOADER */
.loader { width:32px; height:32px; }
 
/* Initial state */
.bar {
    background-color:#99aaca; border:1px solid #96a6c9; float:left;
    margin-right:4px; margin-top:6px; width:6px; height:18px;
    
    /* Set the animation properties */
    animation-duration: 1s;
    animation-iteration-count: infinite;
    animation-name: loadingbar;
}
 
/* Delay both the second and third bar at the start */
.loader .bar:nth-child(2) { animation-delay: 0.1s; }
.loader .bar:nth-child(3) { animation-delay: 0.2s; }
 
/* The actual animation */
@keyframes loadingbar {
     0% { }
    10% { margin-top:5px; height:22px; border-color:#d1d8e6; background-color:#bac5db; }
    20% { margin-top:0px; height:32px; border-color:#d1d7e2; background-color:#c6ccda; }
    30% { margin-top:1px; height:30px; border-color:#d1d8e6; background-color:#bac5db; }
    40% { margin-top:3px; height:26px; }
    50% { margin-top:5px; height:22px; }
    60% { margin-top:6px; height:18px; }
    70% { }
    /* Missing frames will cause the extra delay */
    100% { }
}

CSS

That's all we need! Take note the example uses Prefix free to use unprefixed CSS3 properties, otherwise you would have added prefixes like -webkit-, -moz- etc.

Conclusion & Download

Although I can't find out the specific framerate/speed, I think this animation is pretty cool. Could you make it any better (example: Use less/no extra HTML elements, think about using pseudo elements)?

Demo Facebook loading animation   Download Facebook loading animation

I hope you learned a little bit more from this CSS3 quickie!


Tags:  facebook css3 animation keyframes simple

Interested in this topic? You might enjoy another article I've written called

Did you like this article? Subscribe to my feed or email to keep updated on new articles.

Spread the word and submit to:
Digg!Reddit!Del.icio.us!Facebook!StumbleUpon!
Comments
Add NewSearchRSS
Asa - Web Resources   2012-02-20 10:53:20
Gravatar image Nice, but it will be a few years before this will replace an animated gif in production.

It's good to see the possibilities for use of CSS3 in the future though.
@ShuyithoKruz - CEO   2012-02-25 12:17:38
Gravatar image Super ko0ol... thanx
Logo Desogn - hello   2012-02-28 06:33:27
Gravatar image This is very good to see this tutorial here, which will gonna very useful, thanks for share :)
John - PsdDude   2012-02-29 17:35:37
Gravatar image :idea: very interesting, thanks for sharing!
Kevin   2012-03-08 09:33:46
Gravatar image CSS3 definitely rocks! :) Thank you for sharing these codes. I will definitely implement it!
oyun - oyun, oyun oyna, oyunlar   2012-03-15 15:06:06
Gravatar image css means POWERRRR :D
webmate - webmate   2012-03-19 22:38:37
Gravatar image css3 rules
webmate - webmate   2012-03-19 22:39:21
Gravatar image nice one!!!
BadazxJevon - >>   2012-03-22 16:16:43
Gravatar image It dont fucking work at mii school :evil:
Sajal   2012-03-24 18:33:31
Gravatar image I like the codes and the animation to apply on facebook. Seems to be quite helpful to me. Thanks.
Kat Helms - That's way cool   2012-03-29 02:26:06
Gravatar image I haven't been up on CSS in the last couple years - I find that to be really awesome.

I can see that the power in this isn't in replacing animated gifs - but instead, think of how you can have the equivalent of dynamically created animated gifs.

My only question on this is - how many of these can I have on a page before it starts to slow everything down?
ddmagstuff - great useful resources   2012-04-16 15:43:08
Gravatar image Great collection of very information and resources.I am very thanks for such an great useful resources.This resources are very useful for all users.
Thanks
Mobile Themes World - Nice Tutorial   2012-04-26 09:34:45
Gravatar image Thanks for sharing this awesome tutorial
Think360studio   2012-04-27 12:02:56
Gravatar image :) Wow!!! Its really amazing. I'll definitly put it in my next project. Thanks for sharing this article and for giving valuable description.
Dainis Graveris - 1stwebdesigner - Web Design Blog   2012-05-17 09:16:06
Gravatar image hah, nice quickie :) Quite enjoyable and loading bars always come handy! :) Glad to see you are still working on your tutorials after all this time all the time evolving :)

Btw aren't you getting penalized because of the Title you offer in comments? Very encouraging for spammers..
Bee - Nice!   2012-05-26 18:19:12
Gravatar image Nice tutorial! Thanks for sharing! :)
Ashok rathod - Web Design blog   2012-08-17 11:46:28
Gravatar image Good tutorial but again css3 IE problem :)
Ceba - www.motocms.com   2012-10-07 14:03:53
Gravatar image Cool I like the animation, I will try to implement for my projects, Thanks I would like to tell you about new css framework as well Base is a really simple CSS framework for building responsive websites that work well in all devices. http://matthewhartman.github.com/base/ Take a look, keep working on such tutorials Thanks
Lucas Freitas   2012-10-07 15:40:59
Gravatar image Hi!

Already bookmarked your site, nice work!

But this quickie the second and third bar grow together. Can you please fix it?
erwin - Great   2012-10-15 13:35:58
Gravatar image :lol: well done
Suresh - Sr. Web Designer   2012-10-23 16:31:20
Gravatar image Gr8 tutorial :lol: Thanks for sharing this
cat   2012-12-01 20:51:41
Gravatar image nice :!:
cat   2012-12-01 20:52:03
Gravatar image nice :!:
cat   2012-12-01 20:52:48
Gravatar image Nice :!:
packers and movers Hyderabad - Top Packers and Movers Hyderabad   2013-06-18 06:23:58
Gravatar image thanks for sharing information , i like this page and article CSS3 quickie,The Facebook loading animation.
packers and movers Bangalore - Top Packers and Movers in Bangalore   2013-06-18 06:25:43
Gravatar image great post , i like this page and article and thanks for giving information about CSS3 quickie.
Read more...
Name:
Email:
  Gravatar enabled.
Website:
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
 
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
 
Security Image
Please input the anti-spam code that you can read in the image.
Unsubscribe from e-mail notifications.
 
< Prev   Next >
Subscribe

Subscribe to Marcofolio