I have a lot of .line
s and I am applying a fading animation to them. I am wondering if there is a simple way to somehow stagger the animation timing so each one is triggered one after another (as oppose to all at once). In other words, I want to create an effect where the first .line
would begin fading, then a second later the second .line
would fade, then a second later the third .line
would fade. This only needs to work in Chrome.
div.line { width: 300px; height:5px; background:red;
-webkit-animation: fade 20s infinite;
-webkit-animation-timing-function: linear;
}
@-webkit-keyframes fade {
0% { opacity:1.0; }
50% { opacity:0.0; }
100% { opacity:1.0; }
}
<div class="line"></div>
<div class="line"></div>
...
<div class="line"></div>
The CSS animation-delay property has the following syntax: animation-delay: [time] | initial | inherit; As you can see, there are three possible values: time, initial, and inherit. The first option is [time], which is the number of seconds or milliseconds before the animation starts.
A staggered animation consists of sequential or overlapping animations. To create a staggered animation, use multiple Animation objects. One AnimationController controls all of the Animation s.
The CSS animation-timing function sets the pace of the animation. Meaning, it allows you to control when the animation speeds up and slows down during the animation cycle. It's important to understand that this function does not affect the actual duration of an animation.
default animation-timing-function: ease; The animation starts slowly, accelerates in the middle, and slows down at the end. animation-timing-function: ease-in; The animation starts slowly, and accelerates gradually until the end.
Use nth-child to select each individual line then apply an animation-delay, like so:
.line:nth-child(1) {
-webkit-animation-delay: 1s;
}
.line:nth-child(2) {
-webkit-animation-delay: 2s;
}
A SASS solution might look something like this:
Here's the CodePen
styles.css@import "compass/css3";
.my-element {
@include transition(opacity 0.3s);
@include opacity(0);
@include inline-block;
margin: 5px;
width: 100px;
height: 100px;
background: tomato;
// Loop through the items and add some delay.
@for $i from 1 through 3 {
&:nth-child(#{$i}) {
@include transition-delay(0.1s * $i);
}
}
.my-container:hover & {
@include opacity(1);
}
}
http://codepen.io/anon/pen/tngHy
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With