안녕하세요 저는 JavaScript를 처음 사용하고 있으며 개발중인이 코드에 대한 솔루션을 만드는 데 어려움이 있습니다.
슬라이드 쇼 (다른 이미지로 변경되는 이미지)에 페이드 전환 효과를 추가해야합니다. 이미 존재하는 버튼 외에도 이미지가 자동으로 변경됩니다.
편집 : 다음은 전체 코드는 I (@albert)는 조각에 코드를 넣어 그냥 건너 와서 처음 두 이미지 ...페이드 전환 효과 추가 및 자동 이미지 변경
var slideIndex = 1;
showDivs(slideIndex);
function plusDivs(n) {
showDivs(slideIndex += n);
}
function currentDiv(n) {
showDivs(slideIndex = n);
}
function showDivs(n) {
var i;
var x = document.getElementsByClassName("slides");
var dots = document.getElementsByClassName("active");
if (n > x.length) {slideIndex = 1}
if (n < 1) {slideIndex = x.length}
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" white", "");
}
x[slideIndex-1].style.display = "block";
dots[slideIndex-1].className += " white";
}
.circle{
height:9px;
width:9px;
padding:0;
background-color:#000;
}
.container{
position:relative;
max-width:800px;
max-height:350px;
overflow:hidden;
}
.centered{
text-align:center;
margin-bottom:16px;
font-size:18px;
color:white;
position:absolute;
left:0;
bottom:0;
}
.left-arrow{
float:left;
padding-left:16px;
cursor:pointer
}
.right-arrow{
float:right;
padding-right:16px;
cursor:pointer
}
.arrow:hover{
color:#b4aa50;
}
.arrow{
-webkit-transition:background-color .3s,color .15s,box-shadow
.3s,opacity 0.3s;
transition:background-color .3s,color .15s,box-shadow
.3s,opacity 0.3s;
}
.circle-b{
border:1px solid #fff;
background-color:transparent;
-webkit-transition:background-color .3s,color .15s,box-shadow
.3s,opacity 0.3s;
transition:background-color .3s,color .15s,box-shadow
.3s,opacity 0.3s;
}
.circle-b:hover{
color:#000;
background-color:#fff;
}
.white{
color:#000;background-color:#fff}
}
<div class="container">
<img class="slides" src="https://i.stack.imgur.com/b9ukx.png" style="width:100%">
<img class="slides" src="https://i.stack.imgur.com/wx8jF.png" style="width:100%">
<div class="centered" style="width:100%">
<div class="left-arrow arrow" onclick="plusDivs(-1)">❮</div>
<div class="right-arrow arrow" onclick="plusDivs(1)">❯</div>
<span class="circle active circle-b " onclick="currentDiv(1)"> </span>
<span class="circle active circle-b " onclick="currentDiv(2)"> </span>
</div>
</div>
이것은 순수 CSS에서 가능합니다. 당신은 그 해결책을 신경 써야 할까? 아니면 자바 스크립트가 필요한가? – albert