HTML/CSS Tutorials

Web Design Blog / HTML/CSS Tutorials / CSS3 Loading Animation Loop

CSS3 Loading Animation Loop

Tags:

Hi folks, this time we're going to see and create three CSS3 animation loop, can be used in many fields, such as preloader for images with jQuery. I remember this animations are only visible in Firefox, Safari and Chrome. Let's see how to create it.

CSS3 Loading Animation Loop Full

First Example CSS3 Loading Animation Loop

CSS3 Loading Animation Loop - First Example

HTML

In this first example, create only two div and thanks to the border-radius property, they will take the circle shape.

<div class="ball"></div>
<div class="ball1"></div>

CSS

For the CSS style is very simple, just play with the parameters for the graphic you want, as regards the animation simply use the transform:rotateproperty.

.ball {
	background-color: rgba(0,0,0,0);
	border:5px solid rgba(0,183,229,0.9);
	opacity:.9;
	border-top:5px solid rgba(0,0,0,0);
	border-left:5px solid rgba(0,0,0,0);
	border-radius:50px;
	box-shadow: 0 0 35px #2187e7;
	width:50px;
	height:50px;
	margin:0 auto;
	-moz-animation:spin .5s infinite linear;
	-webkit-animation:spin .5s infinite linear;
}
.ball1 {
	background-color: rgba(0,0,0,0);
	border:5px solid rgba(0,183,229,0.9);
	opacity:.9;
	border-top:5px solid rgba(0,0,0,0);
	border-left:5px solid rgba(0,0,0,0);
	border-radius:50px;
	box-shadow: 0 0 15px #2187e7; 
	width:30px;
	height:30px;
	margin:0 auto;
	position:relative;
	top:-50px;
	-moz-animation:spinoff .5s infinite linear;
	-webkit-animation:spinoff .5s infinite linear;
}
@-moz-keyframes spin {
	0% { -moz-transform:rotate(0deg); }
	100% { -moz-transform:rotate(360deg); }
}
@-moz-keyframes spinoff {
	0% { -moz-transform:rotate(0deg); }
	100% { -moz-transform:rotate(-360deg); }
}
@-webkit-keyframes spin {
	0% { -webkit-transform:rotate(0deg); }
	100% { -webkit-transform:rotate(360deg); }
}
@-webkit-keyframes spinoff {
	0% { -webkit-transform:rotate(0deg); }
	100% { -webkit-transform:rotate(-360deg); }
}

Second Example CSS3 Loading Animation Loop

CSS3 Loading Animation Loop - Second Example

HTML

The second example is the same as the precedent for the markup, the main difference you'll find it in the CSS.

<div class="circle"></div>
<div class="circle1"></div>

CSS

Simply in this example we are going to act on the rotation, and more we insert an animation that will allow us to have an pulse effect. This effect will be active only in the first circle.

.circle {
	background-color: rgba(0,0,0,0);
	border:5px solid rgba(0,183,229,0.9);
	opacity:.9;
	border-right:5px solid rgba(0,0,0,0);
	border-left:5px solid rgba(0,0,0,0);
	border-radius:50px;
	box-shadow: 0 0 35px #2187e7;
	width:50px;
	height:50px;
	margin:0 auto;
	-moz-animation:spinPulse 1s infinite ease-in-out;
	-webkit-animation:spinPulse 1s infinite linear;
}
.circle1 {
	background-color: rgba(0,0,0,0);
	border:5px solid rgba(0,183,229,0.9);
	opacity:.9;
	border-left:5px solid rgba(0,0,0,0);
	border-right:5px solid rgba(0,0,0,0);
	border-radius:50px;
	box-shadow: 0 0 15px #2187e7; 
	width:30px;
	height:30px;
	margin:0 auto;
	position:relative;
	top:-50px;
	-moz-animation:spinoffPulse 1s infinite linear;
	-webkit-animation:spinoffPulse 1s infinite linear;
}
@-moz-keyframes spinPulse {
	0% { -moz-transform:rotate(160deg); opacity:0; box-shadow:0 0 1px #2187e7;}
	50% { -moz-transform:rotate(145deg); opacity:1; }
	100% { -moz-transform:rotate(-320deg); opacity:0; }
}
@-moz-keyframes spinoffPulse {
	0% { -moz-transform:rotate(0deg); }
	100% { -moz-transform:rotate(360deg);  }
}
@-webkit-keyframes spinPulse {
	0% { -webkit-transform:rotate(160deg); opacity:0; box-shadow:0 0 1px #2187e7; }
	50% { -webkit-transform:rotate(145deg); opacity:1;}
	100% { -webkit-transform:rotate(-320deg); opacity:0; }
}
@-webkit-keyframes spinoffPulse {
	0% { -webkit-transform:rotate(0deg); }
	100% { -webkit-transform:rotate(360deg); }
}

Third Example CSS3 Loading Animation Loop

CSS3 Loading Animation Loop - Third Example

HTML

In this latest example we find a simple loop that is animated thanks to the transform:scale property. The markup is longer than its predecessors, but this can vary according to the blocks you want to insert.

<div id="block_1" class="barlittle"></div>
<div id="block_2" class="barlittle"></div>
<div id="block_3" class="barlittle"></div>
<div id="block_4" class="barlittle"></div>
<div id="block_5" class="barlittle"></div>

CSS

Here the style is much easier to handle since we're going to take to apply the effect to animation:delay property of each block.

.barlittle {
	background-color:#2187e7;  
	background-image: -moz-linear-gradient(45deg, #2187e7 25%, #a0eaff); 
	background-image: -webkit-linear-gradient(45deg, #2187e7 25%, #a0eaff);
	border-left:1px solid #111; border-top:1px solid #111; border-right:1px solid #333; border-bottom:1px solid #333; 
	width:10px;
	height:10px;
	float:left;
	margin-left:5px;
        opacity:0.1;
	-moz-transform:scale(0.7);
	-webkit-transform:scale(0.7);
	-moz-animation:move 1s infinite linear;
	-webkit-animation:move 1s infinite linear;
}
#block_1{
 	-moz-animation-delay: .4s;
	-webkit-animation-delay: .4s;
 }
#block_2{
 	-moz-animation-delay: .3s;
	-webkit-animation-delay: .3s;
}
#block_3{
 	-moz-animation-delay: .2s;
	-webkit-animation-delay: .2s;
}
#block_4{
 	-moz-animation-delay: .3s;
	-webkit-animation-delay: .3s;
}
#block_5{
 	-moz-animation-delay: .4s;
	-webkit-animation-delay: .4s;
}
@-moz-keyframes move{
	0%{-moz-transform: scale(1.2);opacity:1;}
	100%{-moz-transform: scale(0.7);opacity:0.1;}
}
@-webkit-keyframes move{
	0%{-webkit-transform: scale(1.2);opacity:1;}
	100%{-webkit-transform: scale(0.7);opacity:0.1;}
}

Conclusion

I hope that with this tutorial you learned how to create simple animations loop using only the CSS3 properties.

Share and Enjoy:

  • Twitter
  • Facebook
  • LinkedIn
  • del.icio.us
  • StumbleUpon
  • Digg
  • Google Buzz
  • Reddit
  • RSS
  • blogmarks
  • Design Float
  • Diigo
  • DZone
  • email
  • FriendFeed
  • Identi.ca
  • Ping.fm
  • Plurk
  • Posterous
  • Slashdot
  • Suggest to Techmeme via Twitter
  • Technorati
  • Tumblr

About The Author

Alessio Atzeni, based in Rome, Italy, is a dedicated web designer and front-end developer with a passion for CSS3. He specializes in CSS and JavaScript web development, and building search engine friendly websites. For more front-end web development tutorials and CSS3 experiments, check out his web design blog. Follow him on Twitter @Bluxart or add him on Google+

40 comments…Add Comment

  1. Bluxart

    Thanks Evan.

  2. David Salazar

    Muy bonito y rĂ¡pido de realizar!.. nice!

  3. Adam

    Very cool! Nice work. Also, I love your transparent “back to top” but wouldn’t it be less obstructed on the left side of the content?

  4. Bluxart

    Thank you, for the “back to top” I preferred to put it on the right as if it were the extension of the sidebar!

  5. Staff

    I can’t even make the demo work :(

  6. Andrea Baccolini

    Carino il problema adesso e trovare uno script per il preload da abbinare in modo che lo stoppi e faccia comparire la pagina caricata =)

  7. Bluxart

    Works only with Firefox, Safari and Chrome!

  8. Sarah

    Thanks for the nice animation loop ! Im not really good in css and have a little problem, maybe someone could give me a hint on how to solve this. I cant get the Positioning of the second Example to work. I want it as an Loading Animation for my Page 20% from the bottom. Everything i try out makes one circle disappear or the animation stops or .. i dont know, could someone give me a Hand please? :)

  9. Bluxart

    Hello Sarah, create a container and put it inside the loading animation.
    I’ve tested and it works, you just to center the container!

    .container {
    position:fixed;
    bottom:20%;
    width:960px; /* Or your width */
    }

  10. Sarah

    Thanks, that worked so far. :D

    But now the circle1 makes problems. After the Animation finishes, circle1 goes around 50px over the normal animation and rotates forever.

    Would you help me again ? ^^

  11. Bluxart

    Post your example in Jsfiddle

  12. Sarah

    I found the bug i implemented hihi. The wrong javascript code, im so stupid sometimes ! :)

    But i sincerely thank you for you help and will to help further, thats not naturally. Awesome css.

    Greetings Sarah

  13. Bluxart

    :) Dont worry Sarah.

  14. Harmony

    Brilliant CSS3 animation, and very neat and easy-to-edit code, thank you for sharing :)

  15. firdaus

    i never thought that this can be done with css3.. Serious You AMAZING

  16. draw a pixel

    Man I love the second animation and all just with CSS3. Gonna explore some more about this stuff. Guess there’s no limits for what is possible.

    Great share !

  17. Bluxart

    As soon as I have some time I will create some other entertainment! I love CSS3.

  18. Neal

    Very very cool.
    Personally, this whole animation stuff is a little too much for me, especially the code. I know they’re practical uses for it, but in this case, I’d probably open up Photoshop or Flash, make the animation that way and export it as an .gif file.

    But the powers of CSS3 are awesome. Great article and tutorial.

  19. guest

    How do i program it in javascript to call the animation to stop after the page loads to a certain point?

    I look at several javascript and jquery link cilcks but none of them seem to have worked?

  20. REDEANDO

    Muy buena animacion, la utilizare en mi blog. Saludos desde Spain.

  21. Luca

    Great Work! Check Opera issues.

  22. NICK

    AWESOME TUTORIAL!!!! Going to start getting real familiar with HTML5 & CSS3. Great concepts to learn…have to phase out and build upon HTML and CSS foundation

  23. Alex

    very nice

  24. Chris

    Nice stuff!!!

  25. Seth

    Awesome stuff, your posts never cease to amaze me! My favorites so far are your Skill Bar Animation ( http://www.alessioatzeni.com/blog/css3-skill-bar-animation/ )
    and your Graph Animation ( http://www.alessioatzeni.com/wp-content/tutorials/html-css/CSS3-Graph-Animation/index.html ). I definitely plan on using the graph for a little experiment on my own site, of course you’ll be getting full credit! ;)

    Keep it up,
    -Seth G.

  26. Amrinder Singh

    I think animation is not possible without J query.

  27. Sumit Nagpal

    Thanks for Sharing.
    i think CSS3 is not work in older browser like IE6,7

  28. Graeme

    Really cool, thanks for this article and nice website too!!!

  29. Mohanraaj

    nice method… whether that play/pause animation working????

  30. Dan

    Thanks for the tutorial! This is awesome. I was actually working on using it for a personal project but ran into an issue. It was running great for a while, but then all of a sudden it started getting really slow and making the entire app run slow. I take out the spinning animation and everything runs smoothly again. Has anyone seen something like this where a spinner animation brings the page to a sluggish halt? I really like the spinner animation, but I can’t use it if it slows everything down.

  31. Ajax loaders

    Nice! I also found a generator of those things: http://cssload.net

  32. Chamil

    Wow great

  33. Mi Eindra

    That Great

  34. Niraj

    With your post help, I just made a clock in CSS3 with no javascript. Thanks

    http://webstutorial.com/css3-clock/css3

  35. swati

    nice////

  36. Mark

    Awesome animations. I think I saw these on the computer screen in the movie Tron. Sweet stuff.

  37. wisnu

    wooow cool…

  38. Wu Feng

    Please publish the example for Visual Basic thank you.

  39. jut4w4n

    nice tutorial, thank

Leave a response

Sponsored By