CSS3动画应停在75%的位置

时间:2015-04-30 07:28:33

标签: css3 css-animations

是否可以将CSS3动画停留在75%并且不应该再次显示为0%或至少使延迟为75%持续10秒?现在,当动画完成时,它显示在0%位置

div {
  width: 100px;
  height: 100px;
  background-color: red;
  position: relative;
  -webkit-animation-name: example;
  /* Chrome, Safari, Opera */
  -webkit-animation-duration: 4s;
  /* Chrome, Safari, Opera */
  animation-name: example;
  animation-duration: 4s;
}
/* Chrome, Safari, Opera */

@-webkit-keyframes example {
  0% {
    background-color: red;
    left: 0px;
    top: 0px;
  }
  25% {
    background-color: yellow;
    left: 200px;
    top: 0px;
  }
  50% {
    background-color: blue;
    left: 200px;
    top: 200px;
  }
  75% {
    background-color: green;
    left: 0px;
    top: 200px;
  }
}
<div></div>

1 个答案:

答案 0 :(得分:0)

我对您的动画进行了一些更改,您需要做的就是复制75%动画两次,然后使用animation-fill-mode属性并将其设置为forwards以停止动画在最后一个位置。

Demo

div {
    width: 100px;
    height: 100px;
    background-color: red;
    position: relative;
    -webkit-animation-name: example; /* Chrome, Safari, Opera */
    -webkit-animation-duration: 4s; /* Chrome, Safari, Opera */
    animation-name: example;
    animation-duration: 4s;

    /* add these properties */
    -webkit-animation-fill-mode: forwards;
    animation-fill-mode: forwards;
}

/* Chrome, Safari, Opera */
@-webkit-keyframes example {
    0%   {background-color:red; left:0px; top:0px;}
    25%  {background-color:yellow; left:200px; top:0px;}
    50%  {background-color:blue; left:200px; top:200px;}
    75%  {background-color:green; left:0px; top:200px;}
    /* add the below one */
    100%  {background-color:green; left:0px; top:200px;}
}