我正在尝试在 html 中对我的照片创建淡入和淡出效果。显示图像时如何将css中的关键帧调用为javascript?
我必须使用 javascript 作为幻灯片要求的一部分
好像我必须插入.classlist.add?
var slideIndex = 0;
showSlides();
function showSlides() {
var i;
var slides = document.getElementsByClassName("fade");
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
slideIndex++;
if (slideIndex > slides.length) {
slideIndex = 1
}
slides[slideIndex - 1].style.display = "block";
setTimeout(showSlides, 5000);
}
@keyframes fadein {
from {
opacity: .4
}
to {
opacity: 1
}
}
@keyframes fadeout {
from {
opacity: .4
}
to {
opacity: 1
}
}
<!-- Images used for slideshow -->
<div class="fade">
<figure><img class="img-fluid" src=https://via.placeholder.com/150
C/O https://placeholder.com/"></figure>
</div>
<div class="fade">
<figure><img class="img-fluid" src="https://via.placeholder.com/150
C/O https://placeholder.com/"> </figure>
</div>
<div class="fade">
<figure><img class="img-fluid" src="https://via.placeholder.com/150
C/O https://placeholder.com/"></figure>
</div>
<div class="fade">
<figure><img class="img-fluid" src="https://via.placeholder.com/150
C/O https://placeholder.com/"></figure>
</div>
<div class="fade">
<figure><img class="img-fluid" src="https://via.placeholder.com/150
C/O https://placeholder.com/eg"></figure>
</div>
</div>