我尝试在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>
1条答案
按热度按时间gwbalxhn1#
您不需要为此设置关键帧:
更新:应OP要求的ES5版本:
一个一个三个一个一个一个一个一个四个一个一个一个一个一个五个一个