CSS3动画——@keyframes规则和animation属性
来源:互联网 发布:信达期货软件 编辑:程序博客网 时间:2024/05/21 07:55
简介:@keyframes定义关键帧,即动画每一帧执行的是什么,animation是来定义动画的每一帧如何执行的。
一.@keyframe
- 语法:
@keyframes animationname {keyframes-selector {css-styles;}}
animationname是动画名字;keyframes-selector帧选择器,用百分比定义,0%-100%,与from-to等价,作用是定义不同时间段的不同样式。 - 用法:
@keyframes mymove{0% {top:0px;}25% {top:200px;}50% {top:100px;}75% {top:200px;}100% {top:0px;}}
二. animation
该属性有8个动画属性,如下:
- animation-name:keyframes名称;
- animation-duration: 指定完成动画所花费的时间,单位为秒(s)或毫秒(ms);
- animation-timing-function:
指定动画的速度曲线,该属性就不详细解释了,与transition的transition-timing-function相同,可见博客:http://blog.csdn.net/picking_up_stones/article/details/54866147 - animation-delay:指定在动画开始之间的延迟,单位为秒(s)或毫秒(ms),若为负值表示跳过前几秒执行;
- animation-iteration-count: 指定动画应该播放的次数,默认为1次,自己也可以定义播放次数,如2, 3,
4…….,以及无限次infinite; animation-direction:指定是否应该轮流反向播放动画。
a. normal:默认值,动画按正常播放;
b. reverse:动画反向播放;
c. alternate:动画在奇数次正向播放,在偶数次反向播放;
d. alternate-reverse:动画在奇数次反向播放,在偶数次正向播放;
e. initial:设置该属性为它的默认值;
f. inherit:从父元素继承该属性。
animation-fill-mode:指定当动画不播放时要应用到的样式(当动画完成时或动画有一个延迟未开始播放时)
a. none:默认值,表示动画将按预期进行和结束,在动画完成其最后一帧时,动画会反转到初始帧处
b. forwards:表示动画在结束后继续应用最后的关键帧的位置
c. backwards:会在向元素应用动画样式时迅速应用动画的初始帧
d. both:元素动画同时具有forwards和backwards效果
animation-play-state:指定动画是否正在运行或已暂停,当要实现视频播放效果时使用
a. paused:指定动画暂停;
b. running:指定动画运行;
三. 小例子
<!DOCTYPE html><html><head> <title>@keyframe规则和animation动画的练习</title> <style type="text/css"> html,body { margin: 0; padding: 0; } .demo { display: flex; flex-direction: row; justify-content: space-around; background: black; height: 670px; } .demo0 { margin-top: 40%; border-radius: 25px; width: 50px; height: 50px; position: relative; } .demo1 { animation: mymove 4s linear infinite; } .demo2 { animation: mymove 4s ease-in-out 2s infinite; } .demo3 { animation: mymove 4s ease-in infinite; } .demo4 { animation: mymove 4s ease-out 1s infinite; } .demo5 { animation: mymove 5s step-start infinite; } .demo6 { animation: mymove 4s ease 2s infinite; } .demo7 { animation: mymove 4s linear infinite; } .demo8 { animation: mymove 4s ease-in-out 1s infinite; } .demo9 { animation: mymove 4s ease-in infinite; } .demo10 { animation: mymove 4s ease-out 1s infinite; } .demo11 { animation: mymove 5s step-start infinite; } .demo12 { animation: mymove 4s ease 2s infinite; } @keyframes mymove { 0% {top:-100px;background:red;} 25% {top:-200px; background:blue;} 50% {top:-300px; background:yellow;} 75% {top:-400px; background:green;} 100% {top:-500px; background:red;} } </style></head><body><div class="demo"> <div class="demo0 demo1"></div> <div class="demo0 demo2"></div> <div class="demo0 demo3"></div> <div class="demo0 demo4"></div> <div class="demo0 demo5"></div> <div class="demo0 demo6"></div> <div class="demo0 demo7"></div> <div class="demo0 demo8"></div> <div class="demo0 demo9"></div> <div class="demo0 demo10"></div> <div class="demo0 demo11"></div> <div class="demo0 demo12"></div></div></body></html>
运行效果图:
0 0
- CSS3动画——@keyframes规则和animation属性
- CSS3动画animation相关属性与关键帧规则keyframes
- CSS3 animation 属性 CSS3 @keyframes 规则
- CSS3 animation属性 与 @keyframes规则
- CSS3 animation,@keyframes 动画
- 详解css3系列:动画@keyframes和Animation
- 详解css3系列:动画@keyframes和Animation
- 详解css3系列:动画@keyframes和Animation
- 详解css3系列:动画@keyframes和Animation
- CSS3 @keyframes动画规则
- CSS3动画——Keyframes
- css3 @keyframes 动画规则学习
- 【css3】CSS3动画(animation @keyframes)
- CSS3动画--keyframes,transform,animation,transition
- animation属性——css3动画效果
- css3动画animation属性
- css3动画-animation属性
- CSS3 动画 Transitions, Transforms和Animation属性
- StartSSL 免费证书申请步骤以及Tomcat和Apache下的安装
- 由于编码问题引发的ODBC插入数据库中文错误
- C++内置函数(内嵌函数,内联函数)
- oracle笔记(2)----substr使用
- 加法变乘法
- CSS3动画——@keyframes规则和animation属性
- 软件的性能指标
- Activity和Fragment的三种通信以及EventBus通信
- linux下安装jdk
- 前端随笔
- hover方法和toggle方法切换事件
- Zxing生成二维码(可带图标)
- 移动端实现导航的左右滑动
- HBase RegionServer宕机恢复