I am currently using a CSS + Javascript slideshow on my website, inspired by an example from the W3Schools website.
Here is the code I have adapted for my web application:
$(document).ready(function() {
var slideIndex = 1;
function showSlides(n) {
var slides = $(".mySlides");
var i;
if (n > slides.length) {
slideIndex = 1;
}
if (n < 1) {
slideIndex = slides.length;
}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
slides[slideIndex - 1].style.display = "block";
}
function plusSlides(n) {
showSlides(slideIndex += n);
}
showSlides(slideIndex);
$(".prev").click(function() {
plusSlides(-1);
});
$(".next").click(function() {
plusSlides(1);
});
});
@-webkit-keyframes fade {
from {
opacity: .4
}
to {
opacity: 1
}
}
@keyframes fade {
from {
opacity: .4
}
to {
opacity: 1
}
}
.slideshow-container {
position: relative;
margin: auto;
}
.prev,
.next {
cursor: pointer;
position: absolute;
top: 0;
top: 50%;
width: auto;
margin-top: -22px;
padding: 16px;
color: white;
font-weight: bold;
font-size: 18px;
transition: 1.6s ease;
border-radius: 0 3px 3px 0;
}
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
.prev:hover,
.next:hover {
background-color: rgba(0, 0, 0, 0.8);
}
.text {
color: #f2f2f2;
font-size: 15px;
padding: 8px 12px;
position: absolute;
bottom: 8px;
width: 100%;
text-align: center;
}
.numbertext {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
}
.fade {
-webkit-animation-name: fade;
-webkit-animation-duration: 1.5s;
animation-name: fade;
animation-duration: 1.5s;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="slideshow-container">
<div class="mySlides fade">
<div class="numbertext">1 / 3</div>
<img class="img-responsive" src="pic1.jpg" alt='Entrada'>
<div class="text">1</div>
</div>
<div class="mySlides fade">
<div class="numbertext">2 / 3</div>
<img class="img-responsive" src="pic2.jpg">
<div class="text">2</div>
</div>
<div class="mySlides fade">
<div class="numbertext">3 / 3</div>
<img class="img-responsive" src="pic3.jpg">
<div class="text">3</div>
</div>
<a class="prev">❮</a>
<a class="next">❯</a>
</div>
Although the page loads correctly, the pictures disappear after a brief moment. How can I resolve this issue?