colorchange动画为背景

时间:2017-07-07 09:22:41

标签: css animation

我想慢慢更改背景颜色并在css文件中使用此代码:

body {
margin-top:60px;
font-family: sans-serif;
animation: colorchange 50s;
-webkit-animation: colorchange 50s;
     }

@keyframes colorchange{
    0%   {background: #FFCCff;}
   25%  {background: #FFFFCC;}
   50%  {background: #CCCC99;}
   75% {background: #CC9999}
   100%{background:#CCCCFF}
 }

  @-webkit-keyframes colorchange  {
     0%   {background:#FFCCFF;}
     25%  {background: #FFFFCC;}
    50%  {background:  #CCCC99;}
    75% {background: #CC9999;}
    100%{background:#CCCCFF;}
 }

但我希望这种改变永远不会停止,我该怎么做?

2 个答案:

答案 0 :(得分:1)

使用infinite选项:

animation: colorchange 50s infinite;
-webkit-animation: colorchange 50s infinite;

答案 1 :(得分:1)

只需将infinite添加到您的媒体资源中即可。

CSS3 animation Property

body {
margin-top:60px;
font-family: sans-serif;
animation: colorchange 50s infinite;
-webkit-animation: colorchange 50s infinite;
     }

@keyframes colorchange{
    0%   {background: #FFCCff;
   25%  {background: #FFFFCC;
   50%  {background: #CCCC99;
   75% {background: #CC9999
   100%{background:#CCCCFF
 }

  @-webkit-keyframes colorchange  {
     0%   {background:#FFCCFF;}
     25%  {background: #FFFFCC;}
    50%  {background:  #CCCC99;}
    75% {background: #CC9999}
    100%{background:#CCCCFF}
 }