css3 animation change continuously

怎甘沉沦 提交于 2019-12-06 01:01:01

See here: http://jsfiddle.net/9CZFS/1/

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

You need to specify that the animation is going to loop forever.

Also, if you want the animation to be smooth, you'll need to have it start and end with the same value:

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

You just need to tell CSS to infinitely play the animation, it defaults to only playing once. To do this you use animation-iteration-count. Just add the following code to your div style declaration:

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

Here is a demo: http://jsfiddle.net/9CZFS/3/

Documentation for animation-iteration-count: https://developer.mozilla.org/en-US/docs/CSS/animation-iteration-count

Note: My demo also changed your animations to smoothly return to red when it's done:

@keyframes myfirst
{
0%   {background:red;}
25%  {background:yellow;}
50%  {background:blue;}
75% {background:green;}
100%   {background:red;}
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!