【问题标题】:Show content after ends of animation动画结束后显示内容
【发布时间】:2018-02-19 07:27:55
【问题描述】:

我想制作带有延迟的动画 css。第一个 div 必须隐藏,动画结束后我想显示我的 div。但是我的 div 隐藏了之后。

#test p {
  margin-top: 25px;
  font-size: 21px;
  text-align: center;
  opacity: 0;
  animation: fadein 2s linear 2s;
  -moz-animation: fadein 2s linear 2s;
  /* Firefox */
  -webkit-animation: fadein 2s linear 2s;
  /* Safari and Chrome */
  -o-animation: fadein 2s linear 2s;
  /* Opera */
}

@keyframes fadein {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@-moz-keyframes fadein {
  /* Firefox */
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@-webkit-keyframes fadein {
  /* Safari and Chrome */
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@-o-keyframes fadein {
  /* Opera */
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
<div id="test">
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
    dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>

【问题讨论】:

    标签: css css-animations


    【解决方案1】:

    只需将forwardsanimation-fill-mode)与动画一起使用:

    #test p {
      margin-top: 25px;
      font-size: 21px;
      text-align: center;
      opacity: 0;
      animation: fadein 2s linear 2s forwards;
      /*OR
        animation: fadein 2s linear 2s;
        animation-fill-mode:forwards;
        */
    }
    
    @keyframes fadein {
      from {
        opacity: 0;
      }
      to {
        opacity: 1;
      }
    }
    <div id="test">
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
        dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
    </div>

    如你所见here:

    转发

    目标将保留 last 设置的计算值 关键帧在执行过程中遇到。

    【讨论】:

      【解决方案2】:

      似乎删除fadein 2s 之后的linear 2s 允许此工作。

      animation: fadein 2s;
      -moz-animation: fadein 2s; /* Firefox */
      -webkit-animation: fadein 2s; /* Safari and Chrome */
      -o-animation: fadein 2s; /* Opera */
      

      你试图通过结合线性和淡入淡出来完成什么?

      【讨论】:

      • fadein 是动画的名称 :) 线性是一个计时函数 .. 2 秒是延迟 .. 我建议在发布此类答案之前阅读更多关于动画如何工作的信息 ...
      • 是的,我在发布答案之前确实进行了调查,并且该页面上没有定义淡入淡出,这就是我寻求澄清的原因。但请注意,我不否认我还有很多东西要学,并且在某些领域比其他领域知识渊博...
      • 因为fadein是OP定义的动画的名字……看他的代码,看看怎么定义和运行动画
      猜你喜欢
      • 1970-01-01
      • 2017-08-22
      • 1970-01-01
      • 1970-01-01
      • 2012-11-03
      • 1970-01-01
      • 2021-07-23
      • 2015-03-10
      • 2012-03-12
      相关资源
      最近更新 更多