出处:http://blog.csdn.net/dyllove98/article/details/8957232
CSS3中和动画有关的属性有三个 transform、 transition 和 animation。下面来一一说明:
transform
从字面来看transform的释义为改变,使…变形;转换 。这里我们就可以理解为变形。那都能怎么变呢?
none 表示不进行变换;
rotate 旋转 transform:rotate(20deg) 旋转角度可以为负数。需要先有transform-origin定义旋转的基点可为left top center right bottom 或坐标值(50px 70px)。
skew 扭曲 transform:skew(30deg,30deg) skew(相对x轴倾斜,相对y轴倾斜)
scale 缩放 transform:scale(2,3) 横向放大2倍,纵向放大3倍。如等比放大写一个参数即可。
translate 移动 transform:translate(50px, 50px);
matrix 矩阵变形 基本语法transform: matrix(a, c, b, d, tx, ty);其中a, c, b, d是一个二维矩阵:
┌ ┐
│ a b │
│ c d │
└ ┘
a:X轴缩放比例 b:Y轴倾斜 c:Y轴缩放比例 d:X轴倾斜
tx, ty就是就是基于X和Y 坐标重新定位元素。其实就是translate (tx,ty)Transition
W3C标准中对CSS3的transition这是样描述的:“CSS的transition允许CSS的属性值在一定的时间区间内平滑地过渡。这种效果可以在鼠标单击、获得焦点、被点击或对元素任何改变中触发,并圆滑地以动画效果改变CSS的属性值。
transition主要包含四个属性值:
transition-property: 执行变换的属性;
transition- duration: 变换延续的时间:
transition-timing-function: 在延续时间段,变换的速率变化;
transition- delay :变换延迟时间
下面一一说明这四个属性:
transition-property
语法:
transition-property : none | all | [ ]
transition-property是用来指定当元素其中一个属性改变时执行transition效果,其 主要有以下几个值:none(没有属 性改 变);all(所有属性改变)这个也是其默认值;indent(元素属性名);当其值为none时,transition马上停止执行,当指定为all 时,则元素产生任何属性值变化时都将执行transition效果,ident是可以指定元素的某一个属性值。其对应的类型如下:
1、color: 通过红、绿、蓝和透明度组件变换(每个数值单独处理),如:background-color,border-color,color,outline-color等CSS属性;
2、length:真实的数字,如:word-spacing,width,vertical- align,top,right,bottom,left,padding,outline-width,margin,min-width,min- height,max-width,max-height,line-height,height,border-width,border- spacing,background-position等属性;
3、percentage:真实的数字,如:word-spacing,width,vertical- align,top,right,bottom,left,min-width,min- height,max-width,max-height,line-height,height,background-position等属性;
4、integer 离散步骤(整个数字),在真实的数字空间,以及使用floor()转换为整数时发生,如:outline-offset,z-index等属性;
5、number真实的(浮点型)数值,如:zoom,opacity,font-weight等属性;
6、transform list:详情请参阅:《CSS3 Transform》。
7、rectangle:通过x、 y、 width和height(转为数值)变换,如:crop;
8、visibility:离散步骤,在0到1数字范围之内,0表示“隐藏”,1表示完全“显示”,如:visibility;
9、shadow:作用于color、x、y、和blur(模糊)属性,如:text-shadow;
10、gradient:通过每次停止时的位置和颜色进行变化。它们必须有相同的类型(放射状的或是线性的)和相同的停止数值以便执行动画,如:background-image;
11、paint server (SVG):只支持下面的情况:从gradient到gradient以及color到color,然后工作与上面类似;
12、space-separated list of above:如果列表有相同的项目数值,则列表每一项按照上面的规则进行变化,否则无变化;
13、a shorthand property:如果缩写的所有部分都可以实现动画,则会像所有单个属性变化一样变化。
支持执行transition效果的属性:
Property Name | Type |
background-color |
as color |
background-position |
as repeatable list of simple list of length, percentage, or calc |
border-bottom-color |
as color |
border-bottom-width |
as length |
border-left-color |
as color |
border-left-width |
as length |
border-right-color |
as color |
border-right-width |
as length |
border-spacing |
as simple list of length |
border-top-color |
as color |
border-top-width |
as length |
bottom |
as length, percentage, or calc |
clip |
as rectangle |
color |
as color |
font-size |
as length |
font-weight |
as font weight |
height |
as length, percentage, or calc |
left |
as length, percentage, or calc |
letter-spacing |
as length |
line-height |
as either number or length |
margin-bottom |
as length |
margin-left |
as length |
margin-right |
as length |
margin-top |
as length |
max-height |
as length, percentage, or calc |
max-width |
as length, percentage, or calc |
min-height |
as length, percentage, or calc |
min-width |
as length, percentage, or calc |
opacity |
as number |
outline-color |
as color |
outline-width |
as length |
padding-bottom |
as length |
padding-left |
as length |
padding-right |
as length |
padding-top |
as length |
right |
as length, percentage, or calc |
text-indent |
as length, percentage, or calc |
text-shadow |
as shadow list |
top |
as length, percentage, or calc |
vertical-align |
as length |
visibility |
as visibility |
width |
as length, percentage, or calc |
word-spacing |
as length |
z-index |
as integer |
transition-duration
transition-duration是用来指定元素 转换过程的持续时间,取值: