赞助我以写出更好的文章,give me a cup of coffee?css
在css3中,咱们能够经过@keyframes
建立关键帧动画效果。咱们须要将@keyframes
绑定到选择器中,不然不会有效果出现。同时,咱们还需定义动画时长和动画名称前端
@keyframes animationname {keyframes-selector {css-styles;}}
值 | 描述 |
---|---|
animationname | 必需。定义动画的名称。 |
keyframes-selector | 必需。动画时长的百分比。 |
在css3中,咱们以百分比来规定改变发生的时间,或者经过关键词 "from
" 和 "to
",等价于 0% 和 100%。其中,0% 是动画的开始时间,100% 动画的结束时间。css3
另一个重要的属性:animation
git
animation
属性是一个简写属性,用于设置六个动画属性:github
animation-name animation-duration animation-timing-function animation-delay animation-iteration-count animation-direction
注释:请始终规定 animation-duration
属性,不然时长为 0,就不会播放动画了。面试
duration
(持续的时间)segmentfault
语法:动画
animation: name duration timing-function delay iteration-count direction;
值 | 描述 |
---|---|
animation-name | 规定须要绑定到选择器的 keyframe 名称。 |
animation-duration | 规定完成动画所花费的时间,以秒或毫秒计。 |
animation-timing-function | 规定动画的速度曲线。 |
animation-delay | 规定在动画开始以前的延迟。 |
animation-iteration-count | 规定动画应该播放的次数。 |
animation-direction | 规定是否应该轮流反向播放动画。 |
animation-name
属性主要是用来调用@keyframes
定义好的动画。spa
注:animation-name
调用的动画名须要和“@keyframes”定义的动画名称彻底一致(区分大小写),若是不一致将不具备任何动画效果。 .net
语法
animation-direction: normal|alternate;
值 | 描述 |
---|---|
normal | 默认值。动画应该正常播放。 |
alternate | 动画应该轮流反向播放。 |
animation-timing-function 值:
<style type="text/css"> @keyframes changeColor{ 0%{ background: #675AB3; } 20%{ background:#C1E8FF; } 40%{ background:#A48992; } 60%{ background:#FFF900; } 80%{ background:#6D87A0; } 100%{ background: #FFB89A; } } div { width: 400px; height: 150px; background: #E7F0EF; color:black; margin: 50px auto; } div:hover { animation: changeColor 6s ease-in-out .2s; } </style> </head> <body> <div>鼠标移动到我这里,查看动画效果</div> </body>
点击下面的result查看demo:
http://jsfiddle.net/trigkit/0...