【问题标题】:Css animation not keeping at the latest position [duplicate]Css动画没有保持在最新位置[重复]
【发布时间】:2019-02-17 10:31:07
【问题描述】:

嗨,我已经学习 css 2 个月了,所以我遇到了动画问题。 我希望我的代码在石灰完成,但动画完成,并且 div 再次变为红色。

    @keyframes example{
        from{background-color: red}
        to{background-color: lime}
    }


    .animate{
        width:200px;
        height:100px;
        background-color: red;
        animation-name: example;
        animation-direction: alternate;
        animation-duration: 4s;
        animation-iteration-count: 1;
    }

【问题讨论】:

    标签: css css-animations


    【解决方案1】:

    您应该对您的代码执行此操作。

        @keyframes example{
            from{background-color: red}
            to{background-color: lime}
        }
    
    
        .animate{
            width:200px;
            height:100px;
            background-color: red;
            animation-name: example;
            animation-direction: alternate;
            animation-duration: 4s;
            animation-iteration-count: 1;
            animation-fill-mode:forwards;
        }
    

    【讨论】:

      【解决方案2】:

      将背景颜色从红色更改为石灰。

      @keyframes example{
        from{background-color: red}
        to{background-color: lime}
      }
      
      .animate{
        width:200px;
        height:100px;
        background-color: lime;
        animation-name: example;
        animation-direction: alternate;
        animation-duration: 4s;
        animation-iteration-count: 1;
      }
      <div class="animate"></div>

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-01-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多