CSS Animation Fade In pause… Fade Out

耗尽温柔 提交于 2021-02-19 04:05:00

问题


I’m trying to get some (will be images) blocks to fade in pause for a few seconds and then fade out....

I’ve got it so far but it doesn’t seem to want to stay faded out and i’m unsure where i’m going wrong.

After its faded out it then shows up again.

I have a fiddle which shows it very basicly.

/* Defines the animation keyframes */
@-webkit-keyframes fadein {
0% {
     opacity: 0;
 }

 72% {
     opacity: 0;
 }

 100% {
     opacity: 1;
 } 
}
@-moz-keyframes fadein {
  0% {
       opacity: 0;
   }

   72% {
       opacity: 0;
   }

   100% {
       opacity: 1;
   } 
}
@keyframes fadein {
 0% {
      opacity: 0;
  }

  72% {
      opacity: 0;
  }

  100% {
      opacity: 1;
  }

}


/* Defines the animation keyframes */
@-webkit-keyframes fadeOut {
0% {
     opacity: 1;
 }

 72% {
     opacity: 0;
 }

 100% {
     opacity: 0;
 } 
}
@-moz-keyframes fadeOut {
  0% {
         opacity: 1;
     }

     72% {
         opacity: 0;
     }

     100% {
         opacity: 0;
     } 
}
@keyframes fadeOut {
 0% {
        opacity: 1;
    }

    72% {
        opacity: 0;
    }

    100% {
        opacity: 0;
    } 

}

.get{
  -webkit-animation: fadein 1.9s ease-in-out 0s 1, 
    fadeOut 1.9s ease-in-out 5s 1 ; 
 -moz-animation: fadein 1.9s ease-in-out 0s 1, 
    fadeOut 1.9s ease-in-out 5s 1 ;
  animation: fadein 1.9s ease-in-out 0s 1, 
    fadeOut 1.9s ease-in-out 5s 1 ;

   background-color:red;
}



 .give{
   -webkit-animation: fadein 2.8s ease-in-out both 0s 1, 
    fadeOut 1.9s ease-in-out 8s 1 ;  ; 
   -moz-animation: fadein 2.8s ease-in-out both 0s 1, 
    fadeOut 1.9s ease-in-out 8s 1 ; 
   animation: fadein 2.8s ease-in-out both 0s 1, 
    fadeOut 1.9s ease-in-out 8s 1 ; 
     background-color:green;
   }

回答1:


Use a single animation ...

*{
  margin:0;
  padding:0;
}
.block{

  width:100px;
  height:100px
  display:block;
  height:100px;
}


@keyframes fadein {
  0%, 100% {
    opacity: 0;
  }

  72% {
    opacity: 1;
  }

}

.get{
  opacity: 0;
  animation: fadein 2s ease-in-out 0s 1;  
  background-color:red;
}



.give{
  opacity: 0;
  animation: fadein 3s ease-in-out both 1s 1;
  background-color:green;
}
<script src="//cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<div class="block get">Get</div>
<div class="block give">Give</div>


来源:https://stackoverflow.com/questions/26864011/css-animation-fade-in-pause-fade-out

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