CSS3中使用动画,核心是@keyframes规则和animation 属性。@keyframes用于定义动画动作,animation属性指定使用哪个动画,及动画时间。
实例一:
- <style>
- 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 { from {background:red;} to {background:yellow;} }
- @-moz-keyframes myfirst /* Firefox */
- { from {background:red;} to {background:yellow;} }
- @-webkit-keyframes myfirst /* Safari and Chrome */
- { from {background:red;} to {background:yellow;} }
- @-o-keyframes myfirst /* Opera */
- { from {background:red;} to {background:yellow;} }
- </style>
- <div></div>
复制代码
|