Ciao a tutti, premesso che sono alle prime armi con javascript, avrei bisogno di aiuto con questo codice al quale mi servirebbe aggiungere un effetto fade di transizione fra le immagini.Inoltre mi servirebbe che le immagini cambiassero in maniera automatica (in aggiunta alla gi� presente possibilit� di cambiamento tramite bottone). Posto di seguito il codice e ringrazio in anticipo:
Html:
codice HTML:
<div class="container" style="max-width:800px;max-height:350px;overflow:hidden;margin-top:100px;">
<img class="slides" src="example.jpg" style="width:100%">
<img class="slides" src="example2.jpg" 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>
Script:
codice:
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";
}
Css:
codice:
.circle{
cursor:pointer;
height:9px;
width:9px;
padding:0;
background-color:#000;
color:#fff;
display:inline-block;
border-radius:50%;
}
.container{
position:relative;
}
.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}
}