让多个元素依次淡入/淡出,比如5个元素每4秒淡入,
1- 为每个元素制作独特的动画,animation-duration 等于 [ 4s(每个元素的持续时间)* 5(元素数量)] = 20 秒
animation-name: anim1 , anim2, anim3 ...
animation-duration : 20s, 20s, 20s ...
2- 获取每个元素的动画关键帧。
100% (keyframes percentage) / 5 (elements) = 20% (frame for each element)
3- 定义每个动画的起点和终点:
每个动画都有 20% 的帧长度,@keyframes 百分比总是从 0% 开始,
所以第一个动画将从0%开始并在他的帧(20%)结束,
并且每个下一个动画将从上一个动画结束点开始,并在到达他的帧时结束(+ 20%),
@keyframes animation1 { 0% {}, 20% {}}
@keyframes animation2 { 20% {}, 40% {}}
@keyframes animation3 { 40% {}, 60% {}}
and so on
现在我们需要让每个动画的不透明度从0淡入到1,从1到0淡出,
所以我们将在开始之后和结束点之前为每个动画添加另外 2 个点(步骤)以处理完全不透明度(1)
http://codepen.io/El-Oz/pen/WwPPZQ
.slide1 {
animation: fadeInOut1 24s ease reverse forwards infinite
}
.slide2 {
animation: fadeInOut2 24s ease reverse forwards infinite
}
.slide3 {
animation: fadeInOut3 24s ease reverse forwards infinite
}
.slide4 {
animation: fadeInOut4 24s ease reverse forwards infinite
}
.slide5 {
animation: fadeInOut5 24s ease reverse forwards infinite
}
.slide6 {
animation: fadeInOut6 24s ease reverse forwards infinite
}
@keyframes fadeInOut1 {
0% { opacity: 0 }
1% { opacity: 1 }
14% {opacity: 1 }
16% { opacity: 0 }
}
@keyframes fadeInOut2 {
0% { opacity: 0 }
14% {opacity: 0 }
16% { opacity: 1 }
30% { opacity: 1 }
33% { opacity: 0 }
}
@keyframes fadeInOut3 {
0% { opacity: 0 }
30% {opacity: 0 }
33% {opacity: 1 }
46% { opacity: 1 }
48% { opacity: 0 }
}
@keyframes fadeInOut4 {
0% { opacity: 0 }
46% { opacity: 0 }
48% { opacity: 1 }
64% { opacity: 1 }
65% { opacity: 0 }
}
@keyframes fadeInOut5 {
0% { opacity: 0 }
64% { opacity: 0 }
66% { opacity: 1 }
80% { opacity: 1 }
83% { opacity: 0 }
}
@keyframes fadeInOut6 {
80% { opacity: 0 }
83% { opacity: 1 }
99% { opacity: 1 }
100% { opacity: 0 }
}