Maintaining the final state at end of a CSS3 animation

前端 未结 4 1682
天涯浪人
天涯浪人 2020-11-22 07:24

I\'m running an animation on some elements that are set to opacity: 0; in the CSS. The animation class is applied onClick, and, using keyframes, it changes the

4条回答
  •  名媛妹妹
    2020-11-22 07:33

    Use animation-fill-mode: forwards;

    animation-fill-mode: forwards;
    

    The element will retain the style values that is set by the last keyframe (depends on animation-direction and animation-iteration-count).

    Note: The @keyframes rule is not supported in Internet Explorer 9 and earlier versions.

    Working example

    div {
      width: 100px;
      height: 100px;
      background: red;
      position :relative;
      -webkit-animation: mymove 3ss forwards; /* Safari 4.0 - 8.0 */
      animation: bubble 3s forwards;
      /* animation-name: bubble; 
      animation-duration: 3s;
      animation-fill-mode: forwards; */
    }
    
    /* Safari */
    @-webkit-keyframes bubble  {
      0%   { transform:scale(0.5); opacity:0.0; left:0}
        50%  { transform:scale(1.2); opacity:0.5; left:100px}
        100% { transform:scale(1.0); opacity:1.0; left:200px}
    }
    
    /* Standard syntax */
    @keyframes bubble  {
       0%   { transform:scale(0.5); opacity:0.0; left:0}
        50%  { transform:scale(1.2); opacity:0.5; left:100px}
        100% { transform:scale(1.0); opacity:1.0; left:200px}
    }

    The keyframes

提交回复
热议问题