1 关键帧 —

类似于flash定义动画在每个阶段的样式,即帧动画

关键帧的时间单位

  • 数字: 0%、25%、100%等(设置某个时间段内的任意时间点的样式)
  • 字符:form(0%)、to(100%);

    格式

    1. @keyframes 动画名称
    2. {
    3. 动画状态
    4. }
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style>
  5. div
  6. {
  7. width:100px;
  8. height:100px;
  9. background:red;
  10. animation:myfirst 5s;
  11. -moz-animation:myfirst 5s; /* Firefox */
  12. -webkit-animation:myfirst 5s; /* Safari and Chrome */
  13. -o-animation:myfirst 5s; /* Opera */
  14. }
  15. @keyframes myfirst
  16. {
  17. from {background:red;}
  18. to {background:yellow;}
  19. }
  20. @-moz-keyframes myfirst /* Firefox */
  21. {
  22. from {background:red;}
  23. to {background:yellow;}
  24. }
  25. @-webkit-keyframes myfirst /* Safari and Chrome */
  26. {
  27. from {background:red;}
  28. to {background:yellow;}
  29. }
  30. @-o-keyframes myfirst /* Opera */
  31. {
  32. from {background:red;}
  33. to {background:yellow;}
  34. }
  35. </style>
  36. </head>
  37. <body>
  38. <div></div>
  39. <p><b>注释:</b>本例在 Internet Explorer 中无效。</p>
  40. </body>
  41. </html>

格式

@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 和 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;}
}