CSS animation, fade in fade out opacity on automated slideshow

微笑、不失礼 提交于 2020-06-17 00:08:50

问题


I want to make a slideshow where the pictures transition through fade in fade out opacity. it just glooms on the screen and switches to the next picture.

I got it to work but added the other brower webkits and it stopped working. Can't seem to find my mistake.. The slideshow still works.

This is the code:

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

回答1:


Just modify the .fade class to this

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

Because animation-name does not expect a timeinterval, it only expects the 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>



回答2:


you just need to change the property name

from

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

to

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



回答3:


animation-name wont take seconds, only the name. change animation-name to just animation.



来源:https://stackoverflow.com/questions/48175922/css-animation-fade-in-fade-out-opacity-on-automated-slideshow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!