1,使用调速函数控制过渡效果的速度曲线(加速,减速等)
使用调速函数可以设置过渡效果的速度曲线,从而实现过渡效果随着时间来改变其速度。比如:开始很慢然后加速或者开始很快然后减速。
(1)CSS3定义了如下的调速函数:
linear 规定以相同速度开始至结束的过渡效果(等于 cubic-bezier(0,0,1,1))。
ease 规定慢速开始,然后变快,然后慢速结束的过渡效果(cubic-bezier(0.25,0.1,0.25,1))。
ease-in 规定以慢速开始的过渡效果(等于 cubic-bezier(0.42,0,1,1))。
ease-out 规定以慢速结束的过渡效果(等于 cubic-bezier(0,0,0.58,1))。
ease-in-out 规定以慢速开始和结束的过渡效果(等于 cubic-bezier(0.42,0,0.58,1))。
cubic-bezier(n,n,n,n) 在 cubic-bezier 函数中定义自己的值。可能的值是 0 至 1 之间的数值。
(2)调速函数的使用
使用时只需要把调速函数跟在过渡属性的时间参数后面。如果不填的话则使用默认调速函数(ease)
transition: opacity 10s ease-in-out;
(3)使用样例1:
下面通过样例演示各种调速函数的效果区别。鼠标移入方框,方框内的方块会向右移动,同时方块会旋转,边角变圆角,背景色和文字颜色也在改变。这些样式的改变都会有过渡效果,同时由于使用不同的调速函数,过渡的快慢也是有区别的。
<!doctype html> <html lang="en"> <head> <title>hangge.com</title> <style> .trans_box { padding: 20px; *zoom:1; } .trans_list { width: 10%; height: 64px; margin:10px 0; color:#fff; text-align:center; } .linear { -webkit-transition: all 4s linear; -moz-transition: all 4s linear; -o-transition: all 4s linear; transition: all 4s linear; } .ease { -webkit-transition: all 4s ease; -moz-transition: all 4s ease; -o-transition: all 4s ease; transition: all 4s ease; } .ease_in { -webkit-transition: all 4s ease-in; -moz-transition: all 4s ease-in; -o-transition: all 4s ease-in; transition: all 4s ease-in; } .ease_out { -webkit-transition: all 4s ease-out; -moz-transition: all 4s ease-out; -o-transition: all 4s ease-out; transition: all 4s ease-out; } .ease_in_out { -webkit-transition: all 4s ease-in-out; -moz-transition: all 4s ease-in-out; -o-transition: all 4s ease-in-out; transition: all 4s ease-in-out; } .trans_box:hover .trans_list, .trans_box_hover .trans_list { margin-left:89%; color:#333; -webkit-border-radius:25px; -moz-border-radius:25px; -o-border-radius:25px; border-radius:25px; -webkit-transform: rotate(360deg); -moz-transform: rotate(360deg); -o-transform: rotate(360deg); transform: rotate(360deg); } </style> </head> <div id="transBox" class="trans_box"> <div class="trans_list ease">ease<br>(default)</div> <div class="trans_list ease_in">ease-in</div> <div class="trans_list ease_out">ease-out</div> <div class="trans_list ease_in_out">ease-in-out</div> <div class="trans_list linear">linear</div> </div> </html>
(4)使用样例2:
下面通过对柱状图的宽度改变过渡,演示不同调速函数的效果区别。
<!DOCTYPE html> <html> <head> <style> div { margin:10px 0; width:100px; height:50px; background:#2D9900; color:white; font-weight:bold; transition:width 2s; -moz-transition:width 2s; /* Firefox 4 */ -webkit-transition:width 2s; /* Safari and Chrome */ -o-transition:width 2s; /* Opera */ } #div1 {transition-timing-function: linear;} #div2 {transition-timing-function: ease;} #div3 {transition-timing-function: ease-in;} #div4 {transition-timing-function: ease-out;} #div5 {transition-timing-function: ease-in-out;} /* Firefox 4: */ #div1 {-moz-transition-timing-function: linear;} #div2 {-moz-transition-timing-function: ease;} #div3 {-moz-transition-timing-function: ease-in;} #div4 {-moz-transition-timing-function: ease-out;} #div5 {-moz-transition-timing-function: ease-in-out;} /* Safari and Chrome: */ #div1 {-webkit-transition-timing-function: linear;} #div2 {-webkit-transition-timing-function: ease;} #div3 {-webkit-transition-timing-function: ease-in;} #div4 {-webkit-transition-timing-function: ease-out;} #div5 {-webkit-transition-timing-function: ease-in-out;} /* Opera: */ #div1 {-o-transition-timing-function: linear;} #div2 {-o-transition-timing-function: ease;} #div3 {-o-transition-timing-function: ease-in;} #div4 {-o-transition-timing-function: ease-out;} #div5 {-o-transition-timing-function: ease-in-out;} .trans_box:hover div { width:500px; } </style> </head> <body> <div id="transBox" class="trans_box"> <div id="div2" style="top:150px">ease<br>(default)</div> <div id="div3" style="top:200px">ease-in</div> <div id="div4" style="top:250px">ease-out</div> <div id="div5" style="top:300px">ease-in-out</div> <div id="div1" style="top:100px">linear</div> </div> </body> </html>
2,为过渡增加延时
过渡属性还可以添加一个可选的延时,用以将过渡的开始推迟一段时间。下面是一个等待1秒的例子。
延时1秒
<!doctype html> <html lang="en"> <head> <title>hangge.com</title> <style> .trans_box3 { padding: 20px; *zoom:1; } .trans_box3 div{ width:100px; height:50px; background:#2D9900; color:white; font-weight:bold; -webkit-transition: all 2s ease-out 1s; -moz-transition: all 2s ease-out 1s; -o-transition: all 2s ease-out 1s; transition: all 2s ease-out 1s; } .trans_box3:hover div { width:500px; } </style> </head> <div class="trans_box3"> <div>延时1秒</div> </div> </html>
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
更新日志
- 黄乙玲1988-无稳定的爱心肝乱糟糟[日本东芝1M版][WAV+CUE]
- 群星《我们的歌第六季 第3期》[320K/MP3][70.68MB]
- 群星《我们的歌第六季 第3期》[FLAC/分轨][369.48MB]
- 群星《燃!沙排少女 影视原声带》[320K/MP3][175.61MB]
- 乱斗海盗瞎6胜卡组推荐一览 深暗领域乱斗海盗瞎卡组分享
- 炉石传说乱斗6胜卡组分享一览 深暗领域乱斗6胜卡组代码推荐
- 炉石传说乱斗本周卡组合集 乱斗模式卡组最新推荐
- 佟妍.2015-七窍玲珑心【万马旦】【WAV+CUE】
- 叶振棠陈晓慧.1986-龙的心·俘虏你(2006复黑限量版)【永恒】【WAV+CUE】
- 陈慧琳.1998-爱我不爱(国)【福茂】【WAV+CUE】
- 咪咕快游豪礼放送,百元京东卡、海量欢乐豆就在咪咕咪粉节!
- 双11百吋大屏焕新“热”,海信AI画质电视成最大赢家
- 海信电视E8N Ultra:真正的百吋,不止是大!
- 曾庆瑜1990-曾庆瑜历年精选[派森][WAV+CUE]
- 叶玉卿1999-深情之选[飞图][WAV+CUE]