.slider-container {
position: relative;
height: 400px;
overflow: hidden;
}
.slider-image {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
transition: opacity 1s ease-in-out;
}
.slider-image.active {
opacity: 1;
}
top of page
bottom of page
const images = document.querySelectorAll('.slider-image');
let index = 0;
function showImage() {
images[index].classList.add('active');
}
function hideImage() {
images[index].classList.remove('active');
}
function nextImage() {
hideImage();
index = (index + 1) % images.length;
showImage();
}
setInterval(nextImage, 5000);