【发布时间】:2018-05-29 20:24:21
【问题描述】:
我是 CSS3 和 HTML5 的初学者,现在我正在尝试创建一个 HTML5 和 CSS3 网站以编写 PSD 模型。
一旦我开始使用滑块,问题就来了。通常它应该是一个带有 2 张图像的轮播滑块,底部有一个进度条和一个动画,以使其循环工作。
所以,首先我创建了一个主 div,其中包含其他两个 div,其中包含无线电输入,这样我可以让下一个和上一个箭头工作,以便从一张幻灯片传递到另一张幻灯片。
然后,在我的 css 文件中,我创建了带有不透明效果的 @keyframes 以继续进行淡入淡出动画。不幸的是,这并没有像我想象的那样工作,只是箭头而不是淡入淡出动画。
有人可以帮我看看我的代码吗?我会很感激的!
这是我的 HTML5 代码:
@keyframes click{
0%{ opacity:.4;}
100%{opacity:1;}
}
@keyframes fade{
0% {opacity:1}
45% { opacity: 1}
50% { opacity: 0}
95% {opacity:0}
100% { opacity: 1}
}
@keyframes fade2{
0% {opacity:0}
45% { opacity: 0}
50% { opacity: 1}
95% { opacity: 1 }
100% { opacity:0}
}
#i1, #i2{ display: none;}
.slider{
width: 100%;
height: 550px;
margin: 20px auto;
position: rela
}
#first, #second{
position: absolute;
width: 100%;
height: 100%;
}
.previous{
width: 35px;
height: 70px;
position: absolute;
top:40%;
left:0;
background-color: rgba(70, 70, 70,0.6);
border-radius: 0px 50px 50px 0px;
}
.next{
width: 35px;
height: 70px;
position: absolute;
top:40%;
right: 0;
background-color: rgba(70, 70, 70,0.6);
border-radius: 50px 0px 0px 50px;
}
.prev:hover, .next:hover{
transition: .3s;
background-color: rgba(99, 99, 99, 1);
}
.fas.fa-chevron-left{
position: absolute;
left : 0;
top: 30%;
margin-left: 5px;
color: #fff;
font-size: 30px;
}
.fas.fa-chevron-right{
position: absolute;
right: 0;
top: 30%;
margin-right: 5px;
color: white;
font-size: 30px;
}
.slider div#first {
background: url('img1.jpg') no-repeat center;
background-size: cover;
animation:fade 30000s infinite linear;
-webkit-animation:fade 30000s infinite linear;
}
.slider div#second{
background: url('img2.jpg') no-repeat center;
background-size: cover;
animation: fade2 30000ms infinite linear;
-webkit-animation: fade2 30000ms infinite linear;
}
.slide{z-index:-1;}
#i1:checked ~ #first,
#i2:checked ~ #second
{z-index: 10; animation: click 1s ease-in-out;}
<body>
<div class="slider">
<input type="radio" id="i1" name="images" checked />
<input type="radio" id="i2" name="images" />
<div class="slide" id="first">
<h1>WEBAGENCY: L'AGANCE DE TOUS <br> VOS PROJETS !</h1>
<p>Vous avez un projet ? La WebAgency vous aide à les realiser !</p>
<label class="previous" for="i2"><i class="fas fa-chevron-left"></i></label>
<label class="next" for="i2"><i class="fas fa-chevron-right"></i></label>
</div>
<div class="slide" id="second">
<label class="previous" for="i1"><i class="fas fa-chevron-left"></i></label>
<label class="next" for="i1"><i class="fas fa-chevron-right"></i></label> </div>
</div>
</body>
【问题讨论】:
-
这很聪明。当您在 jsfiddle.net/n3a1ab5z 中加载功能正常的背景图像 url 时,它似乎按预期工作