Код: Выделить всё
const images = [
"https://picsum.photos/id/650/1000",
"https://picsum.photos/id/651/1000",
"https://picsum.photos/id/652/1000",
"https://picsum.photos/id/653/1000",
];
const imgElement = document.getElementById("myImage");
let currentIndex;
function fadeInImage(index) {
imgElement.style.opacity = 0;
imgElement.src = images[index];
let opacity = 0;
imgElement.style.opacity = opacity;
const intervalId = setInterval(() => {
opacity += 0.01;
imgElement.style.opacity = opacity;
if (opacity >= 1) {
clearInterval(intervalId);
}
}, 20);
currentIndex = index;
}
function playImages() {
let randomIndex = Math.floor(Math.random() * images.length);
fadeInImage(randomIndex);
setInterval(() => {
currentIndex = (currentIndex + 1) % images.length;
fadeInImage(currentIndex);
}, 5000);
}
playImages();< /code>
body,
html {
height: 100%;
margin: 0;
padding: 0px;
outline: none;
border: 0px;
}
.homehero {
height: 100%;
}
.homehero img {
height: 100%;
width: 100%;
object-fit: cover;
}< /code>
Подробнее здесь: https://stackoverflow.com/questions/795 ... ransitions