【发布时间】:2018-08-08 12:59:46
【问题描述】:
这是我第一次想使用滑动图像,我在 codepen 上找到了完美的幻灯片,但无法管理它只有 2 或 3 张图像可以滑动。找不到,如何正确设置时间。如果我只需要在每张图像 4 秒内滑动 2 或 3 张图像,它是如何工作的?
@import url('https://fonts.googleapis.com/css?family=Bubblegum+Sans|Ubuntu');
html,
body {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
font-family: 'Bubblegum Sans', cursive;
}
slider {
display: block;
width: 100%;
height: 100%;
background-color: #1f1f1f;
overflow: hidden;
position: absolute;
}
slider > * {
position: absolute;
display: block;
width: 100%;
height: 100%;
background: #1f1f1f;
animation: slide 12s infinite;
overflow: hidden;
}
slide:nth-child(1) {
left: 0;
z-index: 9;
animation-delay: -1s;
background-image: url(https://preview.ibb.co/fm57uG/img_1.jpg);
background-size: cover;
background-position: center;
}
slide:nth-child(2) {
animation-delay: 2s;
background-image: url(https://preview.ibb.co/kkT5gw/img_2.jpg);
z-index: 8;
background-size: cover;
background-position: center;
}
slide:nth-child(3) {
animation-delay: 5s;
background-image: url(https://preview.ibb.co/dVT5gw/img_3.jpg);
background-size: cover;
background-position: center;
z-index: 7;
}
slide:nth-child(4) {
left: 0%;
animation-delay: 8s;
background-image: url(https://preview.ibb.co/m7FU8b/img_4.jpg);
background-size: cover;
background-position: center;
z-index: 6;
}
slide p {
font-size: 70px;
text-align: center;
display: inline-block;
width: 100%;
margin-top: 340px;
color: #fff;
}
@keyframes slide {
0% {
left: 100%;
width: 100%;
}
5% {
left: 0%;
}
25% {
left: 0%;
}
30% {
left: -100%;
width: 100%;
}
30.001% {
left: -100%;
width: 0%;
}
100% {
left: 100%;
width: 0%;
}
}
<slider>
<slide>
<p>Slide 1</p>
</slide>
<slide>
<p>Slide 2</p>
</slide>
<slide>
<p>Slide 3</p>
</slide>
<slide>
<p>Slide 4</p>
</slide>
</slider>
提前致谢!
【问题讨论】: