Reputation: 323
I have a CSS3 Circle Loader that has 3 circles. I am having problems Each circle (starting from the first) should fade out after a few seconds possibly using CSS Animations. Any help is appreciated.
Upvotes: 2
Views: 1840
Reputation: 4605
As others have said, using animations and timing is essencial here.
In fact, each circle is used the same animation,
but you must apply a different delay to each circle.
See below (I'm also using nth-child
instead of first-child
):
.circle span {
/** The same animation to each circle **/
-webkit-animation: circleFade 3s linear infinite;
}
/** Different animation delays **/
.circle span:nth-child(1) { -webkit-animation-delay: 1s; }
.circle span:nth-child(2) { -webkit-animation-delay: 2s; }
.circle span:nth-child(3) { -webkit-animation-delay: 3s; }
/** Animation **/
@-webkit-keyframes circleFade {
0% { background: #ddd; }
25% { background: #999; }
35% { background: #999; }
60% { background: #ddd; }
}
[See the fiddle]
[Now see the fancy fiddle]
Upvotes: 0
Reputation: 7597
Use of keyframes will do it: http://jsfiddle.net/Nux3z/
Couple of details:
1) Use of :nth-child, or :first-child, etc to target your elements
2) Timing of animations: I'm using 1.7, 2.7, rather than 0.7s, 1.4s because I'm allowing for the 1s of fade to finish NOT simply doubling/tripling the time each element takes to animate.
3) Not a solution for IE
Upvotes: 1
Reputation: 10814
I'd go a slightly different route. Only made for webkit but you can alter as needed: http://jsfiddle.net/8kQ2u/17/
@-webkit-keyframes fades {
0%, 100% {
opacity: 1;
}
50% {
opacity: 0;
}
}
.circle span {
display: inline-block;
width: 15px;
height: 15px;
margin: 9.975em auto;
background: #dbdbdb;
-webkit-border-radius: 50px;
-moz-border-radius: 50px;
-ms-border-radius: 50px;
-o-border-radius: 50px;
border-radius: 50px;
-webkit-animation-duration: 1.5s;
-webkit-animation-name: fades;
-webkit-animation-iteration-count: infinite;
}
.circle span:nth-child(2) {
-webkit-animation-delay: 0.2s;
}
.circle span:nth-child(3) {
-webkit-animation-delay: 0.4s;
}
:nth-child
here is fine since I'm pretty sure it has full support in browsers that support @keyframes
. You could use the sibling selector if you prefered (+
).
Upvotes: 3