动画
一段动画,就是一段时间内连续播放n个画面。每一张画面,我们管它叫做“帧”。一定时间内连续快速播放若干个顿,就成了人眼中所看到的动画。同样时间内,播放的帧数越多,画面看起来越流畅。
2.什么是关键帧
关键帧指的是,在构成一段动画的若干帧中,起到决定性作用的 2-3 帧
from和百分比可以混着用,但是一般不建议
动画的简单定义方式
js练习
动画的完整定义方式
js练习
给元素应用动画,用到的属性如下:
1.animation-name: 给元素指定具体的动画 (具体的关键顿)
2. animation-duration : 设置动画所需时间
3 animation-delay : 设置动画延迟
.box (
/* 指定动画 */
animation-name: testKey;
/* 设置动画所需时间 ,这个是必须要写的*/
animation-duration: 5s;
/* 设置动画延退 */
animation-delay: 0.5s;
/*其他属性----start*/
/*设置动画的方式*/
animation-timing-function:linear;
/*动画播放的次数,infinite是无限循环播放*/
animation-iteration-count:infinite;
/*动画的方向*/
animation-direction:alternate;
/*动画以外的状态(不发生动画的时候在哪里)*/
/*animation-fill-mode:forwards;*/
.outer:hover .inner{
/*动画的播放状态*/
animation-play-state:paused;
}
可以设置很多的效果和变换
to{
transform: translate(900px) rotate(360deg);
background-color:purple;
border-radius: 50%;
}
ease:平滑过渡--默认值
linear : 线性过渡
ease-in:慢一快
ease-out : 快一慢
ease-in-out : 慢一快一慢
step-start : 等同于 steps(1,start)
step-end :等同于 steps(1, end)
steps( integer,?): 接受两个参数的步进函数。第一个参数必须为正整数,指定函数的步数。第二个参数取值可以是 start 或 end,指定每一步的值发生变化的时间点。第二个参数默认值为 end,
cubic-bezie(number,number,number,number): 特定的贝赛尔曲线类型
animation-iteration-count ,指定动画的播放次数,常用值如下
1 number:动画循环次数
animation-direction ,指定动画方向,常用值如下:
1. normal:正常方向(默认)
2 reverse: 反方向运行
animation-fill-mode,设置动画之外的状态
1 forwards : 设置对象状态为动画结束时的状态
2backwards : 设置对象状态为动画开始时的状态
animation-play-state ,设置动画的播放状态,常用值如下
1 running: 运动(默认)
2 paused:暂停
动画复合属性
只设置一个时间表示 duration,设置两个时间分别是:duration 和 delay ,其他属性没有数量和顺序要求
.inner (
animation :atguigu 3s 0.5s linear 2 alternate-reverse forwards;
备注: animation-play-state 一般单独使用
过渡和动画的区别
/*用过渡实现inner1跑到右边去*/
.inner1{
background-color:orange;
/*谁发生过渡,给谁加*/
transition:3s linear;
}
/*动画不需要触发条件,过渡需要*/
.outer:hover .inner1{
transform:translate(900px);
}
/*动画可以设置精细的过渡效果,过渡不可以*/
/*用动画实现inner2跑到右边去*/
@keyframes donghua{
0%{}
100%{
transform:translate(900px);
}
}
.inner2{
background-color:green;
animation:donghua 3s linear;
}