CSS @keyframe无效

时间:2013-07-25 07:57:46

标签: css html5 css-transitions css-animations

我一直在经历一些例子,我会在这里错过一些东西。我无法触发这个简单的css动画,改变一些文字的颜色。当我运行下面的示例时,文本保持黑色。

我有一个名为“changeColor”的动画,适用于h1元素的类“text”。它将以5秒的间隔从一种颜色淡化为另一种颜色。

<!DOCTYPE html>
<html>
    <head>
        <style>
            .text{
                display:block;
                -webkit-animation: changeColor 5s infinite; /* Safari 4+ */
                -moz-animation: changeColor 5s infinite; /* Fx 5+ */
                -o-animation: changeColor 5s infinite; /* Opera 12+ */
                animation: changeColor 5s infinite; /* IE 10+ */

            }
            @keyframes changeColor {
              0% {
                color: 'red';
              }

              100% {
                color: 'blue';
              }
            }
            @-moz-keyframes changeColor {
              0% {
                color: 'red';
              }

              100% {
                color: 'blue';
              }
            }
            @-webkit-keyframes changeColor {
              0% {
                color: 'red';
              }

              100% {
                color: 'blue';
              }
            }
        </style>
    </head>
    <body>
        <h1 class="text">Not Working</h1>
    </body>
</html>

2 个答案:

答案 0 :(得分:5)

亲爱的你正在申请css而不是js只是在你的CSS中删除''它会像魅力一样工作

链接是添加http://jsfiddle.net/6Hq8v/

   .text{
                    display:block;
                    -webkit-animation: changeColor 5s infinite; /* Safari 4+ */
                    -moz-animation: changeColor 5s infinite; /* Fx 5+ */
                    -o-animation: changeColor 5s infinite; /* Opera 12+ */
                    animation: changeColor 5s infinite; /* IE 10+ */

                }
                @keyframes changeColor {
                  0% {
                    color: red;
                  }

                  100% {
                    color: blue;
                  }
                }
                @-moz-keyframes changeColor {
                  0% {
                    color: red;
                  }

                  100% {
                    color: blue;
                  }
                }
                @-webkit-keyframes changeColor {
                  0% {
                    color: red;
                  }

                  100% {
                    color: blue;
                  }
                }

答案 1 :(得分:0)

选中此Demonstration

您不需要新的changeColor规则。 这就足够了:

@-webkit-keyframes NAME-YOUR-ANIMATION {
  0%   { color: red; }
  100% { color: blue; }
}

更多动画信息here

相关问题