加入收藏 | 设为首页 | 会员中心 | 我要投稿 焦作站长网 (https://www.0391zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 系统 > 正文

css transition animation的使用(内含贝赛尔曲线详解)

发布时间:2020-05-12 00:56:43 所属栏目:系统 来源:互联网
导读:这篇文章主要介绍了css transition animation的使用(内含贝赛尔曲线详解),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需

在移动开发中直接使用transition动画会让页面变得非常卡顿(亲测),所以我们常用transform:translate3D(0,0,0)或者transform:translateZ(0)来开启移动端动画的gpu加速,使动画过程更流畅。
translate3D(0,0,0)是指电仪3D转换
translateZ(0)是指定义3D转换,只用Z轴

二、animation(动画效果)

因为animation动画是一段持续且循环的动画效果,所以不像transition过渡动画那样简洁,可能会涉及到很复杂的动画效果,所以我们要先学习一下@keyframes规则
该规则是用来创建动画的,说直白点就是告诉元素按哪种动画效果执行

@keyframes语法

@keyframes animationname {keyframes-selector {css-styles;}}

  值 描述
animationname   必需。定义动画的名称。  
keyframes-selector  

必需。动画时长的百分比。

合法的值:

0-100%

from(与 0% 相同)

to(与 100% 相同)

 
css-styles   必需。一个或多个合法的 CSS 样式属性。  

案例

<!DOCTYPE html> <html> <head> <style> div{ width:100px; height:100px; background:red; position:relative; animation:mymove 5s infinite; -moz-animation:mymove 5s infinite; /* Firefox */ -webkit-animation:mymove 5s infinite; /*Safari and Chrome */ -o-animation:mymove 5s infinite; /* Opera */ } @keyframes mymove{ 0% {top:0px;} 25% {top:200px;} 75% {top:50px} 100% {top:100px;} } @-moz-keyframes mymove /* Firefox */{ 0% {top:0px;} 25% {top:200px;} 75% {top:50px} 100% {top:100px;} } @-webkit-keyframes mymove /* Safari and Chrome */{ 0% {top:0px;} 25% {top:200px;} 75% {top:50px} 100% {top:100px;} } @-o-keyframes mymove /* Opera */{ 0% {top:0px;} 25% {top:200px;} 75% {top:50px} 100% {top:100px;} } </style> </head> <body> <p><b>注释:</b>本例在 Internet Explorer 中无效。</p> <div></div> </body> </html>

效果如下:

说明

也就是说keyframes允许你设置在不同的时间段执行不同的动画效果

css3 动画属性 

属性 描述 CSS

@keyframes

  规定动画。   3  

animation

  所有动画属性的简写属性,除了 animation-play-state 属性。   3  

animation-name

  规定 @keyframes 动画的名称。   3  

animation-duration

  规定动画完成一个周期所花费的秒或毫秒。默认是 0。   3  

animation-timing-function

  规定动画的速度曲线。默认是 "ease"。   3  

animation-delay

  规定动画何时开始。默认是 0。   3  

animation-iteration-count

  规定动画被播放的次数。默认是 1。   3  

animation-direction

  规定动画是否在下一周期逆向地播放。默认是 "normal"。   3  

animation-play-state

  规定动画是否正在运行或暂停。默认是 "running"。   3  

animation-fill-mode

  规定对象动画时间之外的状态。   3  

<!DOCTYPE html> <html> <head> <style> div{ width:100px; height:100px; background:red; position:relative; animation:myfirst 5s linear 2s infinite alternate; -moz-animation:myfirst 5s linear 2s infinite alternate;/* Firefox: */ -webkit-animation:myfirst 5s linear 2s infinite alternate;/* Safari and Chrome: */ -o-animation:myfirst 5s linear 2s infinite alternate;/* Opera: */ } @keyframes myfirst{ 0% {background:red; left:0px; top:0px;} 25% {background:yellow; left:200px; top:0px;} 50% {background:blue; left:200px; top:200px;} 75% {background:green; left:0px; top:200px;} 100% {background:red; left:0px; top:0px;} } @-moz-keyframes myfirst /* Firefox */{ 0% {background:red; left:0px; top:0px;} 25% {background:yellow; left:200px; top:0px;} 50% {background:blue; left:200px; top:200px;} 75% {background:green; left:0px; top:200px;} 100% {background:red; left:0px; top:0px;} } @-webkit-keyframes myfirst /* Safari and Chrome */{ 0% {background:red; left:0px; top:0px;} 25% {background:yellow; left:200px; top:0px;} 50% {background:blue; left:200px; top:200px;} 75% {background:green; left:0px; top:200px;} 100% {background:red; left:0px; top:0px;} } @-o-keyframes myfirst /* Opera */{ 0% {background:red; left:0px; top:0px;} 25% {background:yellow; left:200px; top:0px;} 50% {background:blue; left:200px; top:200px;} 75% {background:green; left:0px; top:200px;} 100% {background:red; left:0px; top:0px;} } </style> </head> <body> <p><b>注释:</b>本例在 Internet Explorer 中无效。</p> <div></div> </body> </html>

效果如下:

彩蛋

在火狐和谷歌中可以很方便的调处过渡效果时间曲线的定时函数编辑器,只用点击下面的按钮就可以了。

谷歌中:

火狐中:

(编辑:焦作站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

推荐文章
    热点阅读