CSS 动画,淡入淡出自动幻灯片不透明度

CSS animation, fade in fade out opacity on automated slideshow

我想制作一个幻灯片,其中图片通过淡入淡出不透明度进行过渡。它只是在屏幕上变暗并切换到下一张图片。

我让它工作,但添加了其他浏览器 webkit,它停止工作。似乎找不到我的错误..幻灯片仍然有效。

这是代码:

/* Fading animation in css */
.fade {
-webkit-animation-name: fade 5s;
animation-name: fade 5s;
-moz-animation: fade 5s;
-o-animation: fade 5s;
}

@-webkit-keyframes fade {
0% {opacity: 0.2} 
50% {opacity: 1}
100% {opacity:0.2}
}

@-moz-keyframes fade{
    0% {opacity: 0.2} 
  50% {opacity: 1}
  100% {opacity:0}  
}

@keyframes fade {
  0% {opacity: 0.2} 
  50% {opacity: 1}
  100%{opacity: 0.2}
    }
@-o-keyframes fade {
0% {opacity: 0.2} 
  50% {opacity: 1}
  100%{opacity: 0.2}

}

<div class="slideshowcontainer">
        <div class="slideshow fade">
            <img src="images/PSA.PNG">
        </div>
        <div class="slideshow fade">
            <img src="images/OWSA.PNG">
        </div>
        <div class="slideshow fade">
            <img src="images/CEAC.PNG">
        </div>

.fadeclass修改成这个

.fade {
  -webkit-animation: fade 5s;
  animation: fade 5s;
  -moz-animation: fade 5s;
  -o-animation: fade 5s;
}

因为 animation-name 不需要时间间隔,它只需要名称。

.fade {
-webkit-animation: fade 5s;
animation: fade 5s;
-moz-animation: fade 5s;
-o-animation: fade 5s;
}

@-webkit-keyframes fade {
0% {opacity: 0.2} 
50% {opacity: 1}
100% {opacity:0.2}
}

@-moz-keyframes fade{
    0% {opacity: 0.2} 
  50% {opacity: 1}
  100% {opacity:0}  
}

@keyframes fade {
  0% {opacity: 0.2} 
  50% {opacity: 1}
  100%{opacity: 0.2}
    }
@-o-keyframes fade {
0% {opacity: 0.2} 
  50% {opacity: 1}
  100%{opacity: 0.2}

}
<div class="slideshowcontainer">
        <div class="slideshow fade">
            <img src="https://images-na.ssl-images-amazon.com/images/I/71%2BmEwFaoaL._SL1500_.jpg" width="200px" height: "200px">
        </div>
        </div>

您只需更改 属性 名称

来自

.fade {
-webkit-animation-name: fade 5s;
animation-name: fade 5s;
-moz-animation: fade 5s;
-o-animation: fade 5s;
}

.fade {
-webkit-animation: fade 5s;
animation: fade 5s;
-moz-animation: fade 5s;
-o-animation: fade 5s;
}

animation-name 不用秒,只用名字。将 animation-name 更改为 animation