<div id="fadingImage" class="image-styled"></div>
body {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
}
.image-styled {
background-position: center;
background-size: cover;
background-image: url("https://images.unsplash.com/photo-1615568929336-ddfd93ce683a?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1526&q=80");
display: flex;
height: 75vmin;
width: 75vmin;
transition: background 0.5s linear;
}
const imageEl = document.getElementById("fadingImage");
const images = [
"https://images.unsplash.com/photo-1615568929336-ddfd93ce683a?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1526&q=80",
"https://images.unsplash.com/photo-1588250318414-908688966feb?ixlib=rb-1.2.1&ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&auto=format&fit=crop&w=2089&q=80",
"https://images.unsplash.com/photo-1524077410193-2f667f9ab09a?ixlib=rb-1.2.1&ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&auto=format&fit=crop&w=1650&q=80"
];
window.setInterval(changePicture, 5000);
let i = 0;
function changePicture() {
i++;
if (i > images.length - 1) i = 0;
imageEl.style.backgroundImage = `url(${images[i]})`;
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.