How can I adjust this code so that it doesn't fade out straight away? In other words, make the image fade in, sit for a few seconds and then fade back out?
This is my code right now:
<div id="slideshow-example" data-component="slideshow">
<div role="list">
<div class="slide fade">
<img src="https://images.unsplash.com/photo-1486312338219-ce68d2c6f44d?w=752&ixid=dW5zcGxhc2guY29tOzs7Ozs%3D" alt="">
</div>
<div class="slide fade">
<img src="https://images.unsplash.com/photo-1488590528505-98d2b5aba04b?w=750&ixid=dW5zcGxhc2guY29tOzs7Ozs%3D" alt="">
</div>
<div class="slide fade">
<img src="https://images.unsplash.com/photo-1498753427761-548428edfa67?w=889&ixid=dW5zcGxhc2guY29tOzs7Ozs%3D" alt="">
</div>
</div>
</div>
[data-component="slideshow"] .slide {
display: none;
text-align: center;
}
[data-component="slideshow"] .slide.active {
display: block;
}
.fade
{
-webkit-animation: fadeinout 2s linear forwards;
animation: fadeinout 2s linear forwards;
}
@-webkit-keyframes fadeinout {
0%,100% { opacity: 0; }
50% { opacity: 1; }
}
@keyframes fadeinout {
0%,100% { opacity: 0; }
50% { opacity: 1; }
}
var slideshows = document.querySelectorAll('[data-component="slideshow"]');
slideshows.forEach(initSlideShow);
function initSlideShow(slideshow) {
var slides = document.querySelectorAll(`#${slideshow.id} [role="list"] .slide`);
var index = 0, time = 5000;
slides[index].classList.add('active');
setInterval( () => {
slides[index].classList.remove('active');
index++;
if (index === slides.length) index = 0;
slides[index].classList.add('active');
}, time);
}
Please ignore this part, StackOverflow won't let me post because it's "mostly code" even though there's not much more of an explanation I can give towards my issue. If you are confused on my issue however, just ask me and I'll try and explain it more in-depth.