CSS动画,在自动幻灯片放映时淡出不透明度

时间:2018-01-09 20:07:19

标签: html css animation fading

我想制作一个幻灯片,其中图片通过渐弱淡入淡出过渡。它只是屏幕上的阴影并切换到下一张图片。

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

这是代码:

/* 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>

3 个答案:

答案 0 :(得分:3)

只需将.fade类修改为此

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

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

&#13;
&#13;
.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}

}
&#13;
<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>
&#13;
&#13;
&#13;

答案 1 :(得分:3)

您只需更改属性名称

即可

来自

.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;
}

答案 2 :(得分:0)

animation-name不会花费几秒钟,只需要名字。将animation-name更改为animation