CSS 过渡和动画
转换&过渡 Transform Transition
- 转换:
transform: transform-functions对元素进行 2D 或 3D 转换,包括位移、旋转、倾斜和缩放等 - 转换中心:
transform-origin: x-axis y-axis z-axis;- 默认为:
50% 50% 0; - 参数可以为:
length、%、top left right bottom center;
- 默认为:
- 3D 转换嵌套:
transform-style:flat|preserve-3d3D 空间内如何呈现被嵌套元素flat:子元素将不保留其 3D 位置。preserve-3d:子元素将保留其 3D 位置。
- 3D 转换视距:
perspective: number|none透视效果 - 3D 转换基点:
perspective-origin: x-axis y-axis; - 转换元素背面显示:
backface-visibility: visible|hidden; - 2D 转换
- 旋转
rotate(deg) - 倾斜 Skew 单位
degskew(x,y)skewX(x)skewY(y)
- 缩放 Scale 单位:数值
scale(x,y)scaleX(x)scaleY(y)
- 位移 Translate 单位:像素、百分比(相对于自身大小)
translate(x,y)translateX(x)translateY(y)
- 矩阵 Matrix 数学没学好,待定。。。。。
- 旋转
- 3D 转换
- 旋转
rotateX(deg)rotateY(deg)rotateZ(deg)rotate3d(x,y,z,deg)
- 位移
translateX(x)translateY(y)translateZ(z)translate3d(x,y,z)
- 缩放
scaleX(x)scaleY(y)scaleZ(z)scale3d(x,y,z)
- 旋转
- 转换过渡:Transition
transition: property duration timing-function delay;- 过渡属性:
transition-property: none|all|property; - 过渡时间:
transition-duration: time;以秒(s)或毫秒(ms)计时,默认 0 - 过渡曲线:
transition-timing-function: functionlinear:相同速度开始至结束的过渡效果(等于 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 之间的数值。
- 过渡延迟:
transition-delay: time;以秒(s)或毫秒(ms)计时,默认 0
- 过渡属性:
动画 Animation
预定义关键帧状态:
@keyframes frames {
0% {}
50% {}
100% {}
}
.animation {
animation: frames;
}
调用动画:animation: name duration timing-function delay iteration-count direction;
- 动画名称:
animation-name: keyframeName; - 动画时间:
animation-duration: time; - 动画曲线:
animation-timing-function: value;linear动画从头到尾的速度是相同的。ease默认。动画以低速开始,然后加快,在结束前变慢。ease-in动画以低速开始。ease-out动画以低速结束。ease-in-out动画以低速开始和结束。cubic-bezier(n,n,n,n)在 cubic-bezier 函数中自己的值。可能的值是从 0 到 1 的数值。
- 动画延迟:
animation-delay: time;允许负数 - 播放次数:
animation-iteration-count: n|infinite;,infinite无限次 - 反向播放:
animation-direction: normal|alternate; - 动画状态:
animation-play-state: paused|running;