前几天在Qzone上看到css3动画,很是神奇,因此也学习了一下。首先看看效果http://www.css88.com/demo/css3_Animation/css
很悲剧的是css3动画如今只有WebKit内核的浏览器(Safari和Chrome)支持,虽然应用还不是时候,可是效果却不可低估。html
css3动画通常经过鼠标事件或者说状态定义动画,一般咱们能够用CSS中伪类和js中的鼠标事件来定义。css3
动态伪类 | 起做用的元素 | 描述 |
:link | 只有连接 | 未访问的连接 |
:visited | 只有连接 | 访问过的连接 |
:hover | 全部元素 | 鼠标通过元素 |
:active | 全部元素 | 鼠标点击元素 |
:focus | 全部可被选中的元素 | 元素被选中 |
js的事件也能够,好比click,focus,mousemove,mouseover,mouseout等等web
css3动画经过transition属性和其余css属性(颜色,宽高,变形,位置等等)配合来实现。浏览器
transition的语法:css3动画
transition : [<'transition-property'> || <'transition-duration'> || <'transition-timing-function'> || <'transition-delay'> [, [<'transition-property'> || <'transition-duration'> || <'transition-timing-function'> || <'transition-delay'>]]*wordpress
固然这是简写,咱们也能够完整的写:函数
transition-property : none | all | [ <IDENT> ] [ '
,
' <IDENT> ]*;学习transition-duration : <time> [, <time>]*动画
transition-timing-function : ease | linear | ease-in | ease-out | ease-in-out | cubic-bezier(<number>, <number>, <number>, <number>) [, ease | linear | ease-in | ease-out | ease-in-out | cubic-bezier(<number>, <number>, <number>, <number>)]*
transition-delay : <time> [, <time>]*
transition-property:要变化的属性,好比元素变宽则是width,文字颜色要变色这是color;W3C给出了一个可变换属性的列表:
CSS属性 | 改变的对象 |
background-color | 色彩 |
background-image | 只是渐变 |
background-position | 百分比,长度 |
border-bottom-color | 色彩 |
border-bottom-width | 长度 |
border-color | 色彩 |
border-left-color | 色彩 |
border-left-width | 长度 |
border-right-color | 色彩 |
border-right-width | 长度 |
border-spacing | 长度 |
border-top-color | 色彩 |
border-top-width | 长度 |
border-width | 长度 |
bottom | 百分比,长度 |
color | 色彩 |
crop | 百分比 |
font-size | 百分比,长度 |
font-weight | 数字 |
grid-* | 数量 |
height | 百分比,长度 |
left | 百分比,长度 |
letter-spacing | 长度 |
line-height | 百分比,长度,数字 |
margin-bottom | 长度 |
margin-left | 长度 |
margin-right | 长度 |
margin-top | 长度 |
max-height | 百分比,长度 |
max-width | 百分比,长度 |
min-height | 百分比,长度 |
min-width | 百分比,长度 |
opacity | 数字 |
outline-color | 色彩 |
outline-offset | 整数 |
outline-width | 长度 |
padding-bottom | 长度 |
padding-left | 长度 |
padding-right | 长度 |
padding-top | 长度 |
right | 百分比,长度 |
text-indent | 百分比,长度 |
text-shadow | 阴影 |
top | 百分比,长度 |
vertical-align | 百分比,长度,关键词 |
visibility | 可见性 |
width | 百分比,长度 |
word-spacing | 百分比,长度 |
z-index | 正整数 |
zoom | 数字 |
该取值还有个强大的“all”取值,表示上表全部属性;
除了以上属性外,固然还有css3中大放异彩的css3变形,好比放大缩小,旋转斜切,渐变等等。
transition-duration :动画执行的时间,以秒为单位,好比0.1秒能够写成”0.1s”或者”.1s”,注意后面有个“s”单位。
transition-timing-function :动画执行的计算方式,这里时间函数是使人崩溃的贝塞尔曲线,幸亏css3提过了几个取值:
ease:逐渐慢下来,函数等同于贝塞尔曲线(0.25, 0.1, 0.25, 1.0).
linear:线性过分,函数等同于贝塞尔曲线(0.0, 0.0, 1.0, 1.0).
ease-in:由慢到快,函数等同于贝塞尔曲线(0.42, 0, 1.0, 1.0).
ease-out:由快到慢, 函数等同于贝塞尔曲线(0, 0, 0.58, 1.0).
ease-in-out:由慢到快在到慢, 函数等同于贝塞尔曲线(0.42, 0, 0.58, 1.0)
cubic-bezier:特定的cubic-bezier曲线。 (x1, y1, x2, y2)四个值特定于曲线上点P1和点P2。全部值需在[0, 1]区域内,不然无效。
transition-delay:在动做和变换开始之间等待多久,一般用秒来表示(好比, .1s)。若是你不想延迟,该值可省略。
常常会碰到同一元素会有多个动画同时执行的时侯,好比文字颜色和背景同时变化:
-webkit-transition: color .25s linear , background-color 1s linear;
这时候transition-property建议取值为“all”;关于css3 transform(变形)属性请查看
http://www.css88.com/archives/2168
好比放大缩小:
#blah { -webkit-transition: all .3s ease-in-out; }
#blah:hover { -webkit-transform: scale(1.5); }
旋转:
.arrow { -webkit-transition: all 1s ease-in-out;}
.arrow:hover {-webkit-transform: rotate(720deg);}
作了几个案例,demo:http://www.css88.com/demo/css3_Animation/
还能够看老外的demo:http://webdeveloperjuice.com/demos/css/css3effects.html
=================
参考阅读:
http://www.qianduan.net/css-transitions-101.html
http://www.zhangxinxu.com/wordpress/?p=498
http://fis.io/css-3-hover-animations.html
其余文章:
https://developer.mozilla.org/zh-CN/docs/CSS/Tutorials/Using_CSS_transitions
http://www.qianduan.net/css-transitions-101.html
http://www.w3school.com.cn/css3/css3_animation.asp
http://www.w3school.com.cn/cssref/pr_transition.asp