【问题标题】:css3 animation change continuouslycss3动画不断变化
【发布时间】:2012-12-08 21:53:56
【问题描述】:

我正在尝试实现 css3 动画.... 我正计划改变我的目标在循环中不断影响 但问题是在一个循环后它以红色停止,它不会进一步改变它的颜色...... 如何继续循环......

http://jsfiddle.net/9CZFS/

在下面提供我的代码

div
{
width:100px;
height:100px;
background:red;
animation:myfirst 5s;
-moz-animation:myfirst 5s; /* Firefox */
-webkit-animation:myfirst 5s; /* Safari and Chrome */
-o-animation:myfirst 5s; /* Opera */
}

@keyframes myfirst
{
0%   {background:red;}
25%  {background:yellow;}
50%  {background:blue;}
100% {background:green;}
}

@-moz-keyframes myfirst /* Firefox */
{
0%   {background:red;}
25%  {background:yellow;}
50%  {background:blue;}
100% {background:green;}
}

@-webkit-keyframes myfirst /* Safari and Chrome */
{
0%   {background:red;}
25%  {background:yellow;}
50%  {background:blue;}
100% {background:green;}
}

@-o-keyframes myfirst /* Opera */
{
0%   {background:red;}
25%  {background:yellow;}
50%  {background:blue;}
100% {background:green;}
}

【问题讨论】:

    标签: css css-animations


    【解决方案1】:

    请看这里:http://jsfiddle.net/9CZFS/1/

    animation:myfirst 5s linear infinite;
                            ----^-----
    

    您需要指定动画将永远循环播放。

    另外,如果你想让动画流畅,你需要让它以相同的值开始和结束:

    0%,100%   {background:red;}
    25%  {background:yellow;}
    50%  {background:blue;}
    75% {background:green;}
    

    【讨论】:

      【解决方案2】:

      你只需要告诉 CSS 无限播放动画,它默认只播放一次。为此,您使用animation-iteration-count。只需将以下代码添加到您的 div 样式声明中:

      -moz-animation-iteration-count: infinite;
      -webkit-animation-iteration-count: infinite;
      -o-animation-iteration-count: infinite;
      

      这是一个演示:http://jsfiddle.net/9CZFS/3/

      animation-iteration-count 的文档:https://developer.mozilla.org/en-US/docs/CSS/animation-iteration-count

      注意:我的演示还更改了您的动画以在完成后平滑地返回红色:

      @keyframes myfirst
      {
      0%   {background:red;}
      25%  {background:yellow;}
      50%  {background:blue;}
      75% {background:green;}
      100%   {background:red;}
      }
      

      【讨论】:

        猜你喜欢
        • 2013-06-06
        • 1970-01-01
        • 1970-01-01
        • 2012-08-11
        • 1970-01-01
        • 1970-01-01
        • 2013-08-29
        • 2012-06-17
        • 1970-01-01
        相关资源
        最近更新 更多