怎么在CSS3中使用动画动画属性

  介绍

本篇文章为大家展示了怎么在CSS3中使用动画动画属性,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

要使用动画动画,先要熟悉一下关键帧,帧的语法规则:命名是由“@keyframes”开的头,后面紧接着是这个“动画的名称“加上一对花括号“{}”括号中就是一些不同时间段样式规则。不同关键帧是通过的(相当于0%),到(相当于100%)或百分比来表示(为了得到最佳的浏览器支持,建议使用百分比),如下定义一个简单的动画:

<李>


<李> @keyframes  myfirst /*定义动画名*/,,   ,,,{,,   0%,,,,,,{背景:红色,,左:0 px;,上图:0 px;},/*定义起始帧样式,0%可以换成从*/,,   25%,,,,,{背景:黄色;,左:200 px;,上图:0 px;},,,   50%,,,,,{背景:蓝色;,左:200 px;,最高:200 px;},,,   75%,,,,,{背景:绿色的;,左:0 px;,最高:200 px;},,,   ,,,,100%{背景:红色,,左:0 px;,上图:0 px;},/*定义结束帧样式,100%可以换成*/,,   ,,,}


@keyframes定义好了,要使其能发挥效果,必须通过动画把它绑定到一个选择器,否则动画不会有任何效果。下面列出了动画的属性:

怎么在CSS3中使用动画动画属性

下面设置上述的所有属性

<李>


<李> animation-name:我,我,,,   动画:5 s;,,,   animation-timing-function:线性;,,,   animation-delay: 1,,,,   animation-iteration-count:无限的,,,,   动画方向:备用;,,,   animation-play-state:运行;

上述所有代码可以如下简写:

<李>

动画:myfirst  5 s  linear  2 s  infinite 备用;,,

<李>

animation-play-state:运行;,,

<李>,

,

<强>浏览器兼容性

ie, Firefox以及歌剧支持@keyframes规则和动画属性。

Chrome和Safari需要前缀webkit -。

<强> Internet Explorer 9日以及更早的版本,不支持@keyframe规则或动画属性。

<李>


<李> & lt; ! DOCTYPE  html>,,   & lt; html  lang=癳n"祝辞,,   & lt; head>,,   ,,,& lt; meta  charset=癠TF-8"祝辞,,   ,,,& lt; title>动画演示& lt;/title>,,   ,,,& lt; style>,,,,   ,,,div ,,   ,,,{,,   ,,,宽度:100 px;,,,   ,,,身高:100 px;,,,   ,,,背景:红色,,,,   ,,,位置:相对,,,,   ,,,animation-name:我,我,,,   ,,,动画:5 s,,,,   ,,,animation-timing-function:线性,,,,   ,,,animation-delay: 1,,,,   ,,,animation-iteration-count:无限的,,,,   ,,,动画方向:交替,,,,   ,,,animation-play-state:跑步,,,,   ,,,/*,Safari 以及Chrome:, */,,,   ,,,-webkit-animation-name:我,我,,,   ,,,-webkit-animation-duration: 5 s,,,,   ,,,-webkit-animation-timing-function:线性,,,,   ,,,-webkit-animation-delay: 1,,,,   ,,,-webkit-animation-iteration-count:无限的,,,,   ,,,-webkit-animation-direction:交替,,,,   ,,,-webkit-animation-play-state:跑步,,,,   ,,,},,,   ,,   ,,,@keyframes  myfirst /*定义动画名*/,,,   ,,,{,,   0%,,,,,,{背景:红色,,左:0 px;,上图:0 px;},/*定义起始帧样式,0%相当于从*/,,,   25%,,,,,{背景:黄色;,左:200 px;,上图:0 px;},,,   50%,,,,,{背景:蓝色;,左:200 px;,最高:200 px;},,,   75%,,,,,{背景:绿色的;,左:0 px;,最高:200 px;},,,   ,,,,100%{背景:红色,,左:0 px;,上图:0 px;},/*定义结束帧样式,100%相当于*/,,,   ,,,},,,   ,,   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

怎么在CSS3中使用动画动画属性