纯css3 轮播图 利用keyframes

效果:

 

关键点:利用keyframes 原理:infinite

注意点:在处理关键帧动画的时候,注意处理好 总共花费的 animation-duration:time  与每帧延延迟的时间的交错;要让动画显得层次感,处理好 每帧的延迟时间;

 

多注意时间的穿插 ;效果更很好;下面只是我的小插图;画的不一定对;

 

 

 

以下是我的代码;有兴趣拷贝来看看,仅作为我的练习记录;关键帧要兼容其他浏览器,自行补充前缀即可;

 

下面附上源码;

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>纯css轮播图</title>
</head>
 
<body>
 
<style>
*{ margin:0 ; padding:0}
ul,li{ list-style:none; margin:0; padding:0;}
 
.box,
.box:after {
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0px;
    left: 0px;
    z-index: 0;
}
.box:after {
    content: '';
    background: transparent url(../images/pattern.png) repeat top left;
}
.box li span {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0px;
    left: 0px;
    background-size: cover;
    background-position: 50% 50%;
    background-repeat: none; background-color:#333;
    opacity: 0;
    z-index: 0;
    -webkit-backface-visibility: hidden;
    -webkit-animation: imageAnimation 18s linear infinite 0s;
    -moz-animation: imageAnimation 18s linear infinite 0s;
    -o-animation: imageAnimation 18s linear infinite 0s;
    -ms-animation: imageAnimation 18s linear infinite 0s;
    animation: imageAnimation 18s linear infinite 0s;
}
.box li div {
    z-index: 1000;
    position: absolute;
    bottom: 30px;
    left: 0px;
    width: 100%;
    text-align: center;
    opacity: 0;
    -webkit-animation: titleAnimation 18s linear infinite 0s;
    -moz-animation: titleAnimation 18s linear infinite 0s;
    -o-animation: titleAnimation 18s linear infinite 0s;
    -ms-animation: titleAnimation 18s linear infinite 0s;
    animation: titleAnimation 18s linear infinite 0s;
}
.box li div h3 {
    font-family: 'BebasNeueRegular', 'Arial Narrow', Arial, sans-serif;
    font-size: 160px;
    padding: 0 30px;
    line-height: 120px;
    color: rgba(255,255,255,0.8);
}
.box li:nth-child(1) span { background-image: url(../images/love5.jpg) }
.box li:nth-child(2) span {
    background-image: url(../images/love3.jpg);
    -webkit-animation-delay: 6s;
    -moz-animation-delay: 6s;
    -o-animation-delay: 6s;
    -ms-animation-delay: 6s;
    animation-delay: 6s;
}
.box li:nth-child(3) span {
    background-image: url(../images/love1.jpg);
    -webkit-animation-delay: 12s;
    -moz-animation-delay: 12s;
    -o-animation-delay: 12s;
    -ms-animation-delay: 12s;
    animation-delay: 12s;
}
.box li:nth-child(2) div {
    -webkit-animation-delay: 6s;
    -moz-animation-delay: 6s;
    -o-animation-delay: 6s;
    -ms-animation-delay: 6s;
    animation-delay: 6s;
}
.box li:nth-child(3) div {
    -webkit-animation-delay: 12s;
    -moz-animation-delay: 12s;
    -o-animation-delay: 12s;
    -ms-animation-delay: 12s;
    animation-delay: 12s;
}
 
 
@-webkit-keyframes imageAnimation {
    0% {
        opacity: 0;
        -webkit-animation-timing-function: ease-in;
    }
    11% {
        opacity: 1;
        -webkit-transform: scale(1.05);
        -webkit-animation-timing-function: ease-out;
    }
    30% {
        opacity: 1;
        -webkit-transform: scale(1.1);
    }
    35% {
        opacity: 0;
        -webkit-transform: scale(1.1) translateY(-20%);
    }
    49% {
        opacity: 0;
        -webkit-transform: scale(1.1) translateY(-60%);
    }
    100% { opacity: 0 ;  -webkit-transform: scale(1.1) translateY(-100%);}
}
 
 
@-moz-keyframes imageAnimation {
    0% {
        opacity: 0;
        -moz-animation-timing-function: ease-in;
    }
    11% {
        opacity: 1;
        -moz-transform: scale(1.05);
        -moz-animation-timing-function: ease-out;
    }
    30% {
        opacity: 1;
        -moz-transform: scale(1.1);
    }
    35% {
        opacity: 0;
        -moz-transform: scale(1.1) translateY(-20%);
    }
    49% {
        opacity: 0;
        -moz-transform: scale(1.1) translateY(-60%);
    }
    100% { opacity: 0 ;  -moz-transform: scale(1.1) translateY(-100%);}
}
 
 
@keyframes imageAnimation {
    0% {
        opacity: 0;
        animation-timing-function: ease-in;
    }
    11% {
        opacity: 1;
        transform: scale(1.05);
        animation-timing-function: ease-out;
    }
    30% {
        opacity: 1;
        transform: scale(1.1);
    }
    35% {
        opacity: 0;
        transform: scale(1.1) translateY(-20%);
    }
    49% {
        opacity: 0;
        transform: scale(1.1) translateY(-60%);
    }
    100% { opacity: 0 ;  transform: scale(1.1) translateY(-100%);}
}
 
@-webkit-keyframes titleAnimation {
    0% {
        opacity: 0;
        -webkit-transform: translateY(-300%);
    }
    8% {
        opacity: 1;
        -webkit-transform: translateY(0%);
    }
    22% {
        opacity: 1;
        -webkit-transform: translateY(0%);
    }
    28% {
        opacity: 0;
        -webkit-transform: translateY(100%);
    }
    35% { opacity: 0 }
    100% { opacity: 0 }
}
 
 
@-moz-keyframes titleAnimation {
    0% {
        opacity: 0;
        -moz-transform: translateY(-300%);
    }
    8% {
        opacity: 1;
        -moz-transform: translateY(0%);
    }
    22% {
        opacity: 1;
        -moz-transform: translateY(0%);
    }
    28% {
        opacity: 0;
        -moz-transform: translateY(100%);
    }
    35% { opacity: 0 }
    100% { opacity: 0 }
}
 
@keyframes titleAnimation {
    0% {
        opacity: 0;
        transform: translateY(-300%);
    }
    8% {
        opacity: 1;
        transform: translateY(0%);
    }
    22% {
        opacity: 1;
        transform: translateY(0%);
    }
    28% {
        opacity: 0;
        transform: translateY(100%);
    }
    35% { opacity: 0 }
    100% { opacity: 0 }
}
 
/* Show at least something when animations not supported */
.no-cssanimations .box li span{
    opacity: 1;
}
 
 
 
</style>
        <ul class="box">
            <li><span>Image 01</span><div class="title"><h3>第1张</h3></div></li>
            <li><span>Image 02</span><div class="title"><h3>第2张</h3></div></li>
            <li><span>Image 03</span><div class="title"><h3>第3张</h3></div></li>
        </ul>
         
</body>
</html>其他:1,相同参数的可以写在一起;2,可以只有to, 也可以只有类似50%  省略0%和100%;因为后面的会重置前面的样式;

1
 
posted @   surfaces  阅读(2588)  评论(0编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话
点击右上角即可分享
微信分享提示