css3中怎么利用animation实现逐帧动画效果

发布时间:2021-08-10 14:04:19 作者:Leah
来源:亿速云 阅读:118

css3中怎么利用animation实现逐帧动画效果,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

常见用法:

  1. :hover{ animation:mymove  4s ease-out 1s backwards;}   

  2. @-webkit-keyframes mymove /*Safari and Chrome*/ { from {left:0px;} to {left:200px;} }   

  3.   

  4. 解释:   

  5. mymove :keyframes的名称;   

  6. 4s:动画的总时间;     

  7. ease-out: 快结束的时候慢下来;   

  8. 1s:停顿1秒后开始动画;   

  9. backwards:动画结束后回到原点   

  10. 默认:播放一次   

  11.   

  12. 或者   

  13. transition:left 4s ease-out    

  14. :hover{left:200px}   

  15.   


兼容主流浏览器:

CSS Code复制内容到剪贴板

  1. .test{   

  2.   -webkit-animation: < 各种属性值 >;   

  3.      -moz-animation: < 各种属性值 >;   

  4.        -o-animation: < 各种属性值 >;   

  5.           animation: < 各种属性值 >;   

  6.     }   

animation-name,规定要绑定的keyframes的名称,随便你取,不过为了日后维护的方便,建议取一个跟动作相关名称相近的名称比较好。比如要我们要绑定一个跑的动作,那么可以命名为run。

time,这里有两个时间,前面一个是规定完成这个动画所需要的时间,全称叫animation-duration,第二个time为动画延迟开始播放的时间,全称叫animation-delay,这两个数值可以用秒&rsquo;s&rsquo;也可以用微秒&rsquo;ms&rsquo;来写,1000ms=1s,这个不用一一介绍。

animation-timing-function,规定动画的运动曲线,这里有9个值,分别是ease| linear | ease-in | ease-out | ease-in-out | step-start | step-end | steps([, [ start | end ] ]?) | cubic-bezier(x1, y1, x2, y2)

ease:动画缓慢开始,接着加速,最后减慢,默认值;
linear:动画从头到尾的速度是相同的;
ease-in:以低速开始;
ease-out:以低速结束;
ease-in-out:动画以低速开始和结束;

效果一样 (按步数)steps

CSS Code复制内容到剪贴板

  1. .test1{   

  2.  background:url(https://cache.yisu.com/upload/information/20210311/295/11218.png) no-repeat 0 0;   

  3.  -webkit-animation:run 350ms steps(1) infinite 0s;}   

  4. @-webkit-keyframes run {       

  5.     0% {   

  6.            background-position:0;   

  7.     }   

  8.     20% {   

  9.        background-position:-90px 0;   

  10.     }   

  11.     40% {   

  12.        background-position:-180px 0;   

  13.     }   

  14.     60% {   

  15.        background-position:-270px 0;   

  16.     }   

  17.     80% {   

  18.        background-position:-360px 0;   

  19.     }   

  20.     100% {   

  21.        background-position:-450px 0;   

  22.     }   

  23.   

  24. }   

  25. .test2{   

  26.  background:url(https://cache.yisu.com/upload/information/20210311/295/11218.png) no-repeat 0 0;   

  27.  -webkit-animation:run 350ms steps(5) infinite 0s;}   

  28.   

  29. @-webkit-keyframes run {   

  30.     100% {   

  31.        background-position:-450px 0;   

  32.     }   

  33.   

  34. }   

  35.   

animation-iteration-count,动画播放次数,默认值为1,infinite为无限制,假如设置为无限制,那么动画就会不停地播放。

animation-direction,规定动画是否反方向运动。
= normal | reverse | alternate | alternate-reverse
第一个值是正常转动播放,默认值,reverse为反向转动,alternate一开始正常转动,播放完一次之后接着再反向转动,假如设置animation-iteration-count:1则该值无效,alternate-reverse一开始为反向转动,播完一次之后按照回归正常转动,交替转动,设置count为1,则该值无效。
animation-play-state,定义动画是否运行或暂停,这是后来新增的属性,有两个属性值分别是running和paused。默认值为normal,动画正常播放。假如是为paused,那么动画暂停。假如一个动画一开始为运动,那么假如设置paused那么该动画暂停,假如再设置running,那么该动画会从刚才暂停处开始运动
animation-fill-mode,定义动画播放时间之外的状态,顾名思义,要么就是在动画播放完了之后给它一个状态 animation-fill-mode : none | forwards | backwards | both; none,播放完之后不改变默认行为,默认值,forwards则是停在动画最后的的那个画面,backwards则是回调到动画最开始出现的画面,both则应用为动画结束或开始的状态。

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注亿速云行业资讯频道,感谢您对亿速云的支持。

推荐阅读:
  1. css3使用animation属性如何实现背景颜色动态渐变的效果
  2. 怎么在Android中利用animation-list实现一个帧动画效果

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

css3 animation

上一篇:CSS3 中怎么利用text-shadow实现文字阴影效果

下一篇:CSS中怎么利用pointer-events属性实现鼠标穿透效果

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》