Animation CSS3: display + opacity

前端 未结 15 2933
轮回少年
轮回少年 2020-11-27 11:42

I have got a problem with a CSS3 animation.

.child {
    opacity: 0;
    display: none;

    -webkit-transition: opacity 0.5s ease-in-out;
    -moz-transit         


        
15条回答
  •  再見小時候
    2020-11-27 11:52

    To have animation on both ways onHoverIn/Out I did this solution. Hope it will help to someone

    @keyframes fadeOutFromBlock {
      0% {
        position: relative;
        opacity: 1;
        transform: translateX(0);
      }
    
      90% {
        position: relative;
        opacity: 0;
        transform: translateX(0);
      }
    
      100% {
        position: absolute;
        opacity: 0;
        transform: translateX(-999px);
      }
    }
    
    @keyframes fadeInFromNone {
      0% {
        position: absolute;
        opacity: 0;
        transform: translateX(-999px);
      }
    
      1% {
        position: relative;
        opacity: 0;
        transform: translateX(0);
      }
    
      100% {
        position: relative;
        opacity: 1;
        transform: translateX(0);
      }
    }
    
    .drafts-content {
      position: relative;
      opacity: 1;
      transform: translateX(0);
      animation: fadeInFromNone 1s ease-in;
      will-change: opacity, transform;
    
      &.hide-drafts {
        position: absolute;
        opacity: 0;
        transform: translateX(-999px);
        animation: fadeOutFromBlock 0.5s ease-out;
        will-change: opacity, transform;
      }
    }
    

提交回复
热议问题