动效

yuhuo2022-03-07Html/CssCss属性

变换

transform

transform: <变换>#

说明

x 轴为水平轴,正向往右;y 轴为垂直轴,正向往下;z 轴为深度轴,正向往外;

多种变换叠加解析

  1. rotateX(90deg) translateY(100px) 旋转 + 平移

在原点围绕 X 坐标轴向上旋转 90deg,生成新的坐标系(即新的 y 轴是原本的 z 轴,新的 z 轴是原本的 -y 轴)然后根据新的坐标系在 y 轴正向平移;

  1. scaleX(2) translateX(100px) 缩放 + 平移

在原点向 X 轴的拉伸刻度比例为原本的2倍(即 1px 拉伸到 2px 的长度),然后向 X 轴正向平移100px,由于刻度放大了,实际平移了 200px。

  1. rotateX(90deg) scaleY(2) 旋转 + 缩放

旋转后,在生成新的坐标系的 y 轴缩放。

  1. scaleZ(2) rotateX(90deg) 缩放 + 旋转

在 z 轴拉伸刻度比例为原本 2 倍,再旋转,旋转时刻度比例缩放保持在原本的坐标轴上,旋转后原本的 z 轴变成现在的 y 轴,即现在的 y 轴的刻度比例是正常的 2 倍。(就是第3点和第4点最后效果相同)

transform 多种变换叠加 - JSRUN.NETopen in new window

注意

使用变换会使子元素的fixed定位失效;

transform-style

transform-style: <变换类型>#

  • flat:二维平面 默认值
  • preserve-3d:三维空间

注意

transform-style 作用在变换元素的父元素上。

父元素为二维平面时,子元素进行3D变换,只是将各子元素分别变换后的投影贴到父元素上,子元素相互之间,子元素和父元素之间都不会存在空间遮挡关系。旋转父元素,可验证父元素及子元素是处在一个平面中。

父元素为三维空间时,子元素进行3D变换,是真实的空间操作,会存在相互交叉遮挡,旋转父元素,可验证父元素及内部变换元素是处在一个空间中。

transform-style 3D测试 - JSRUN.NETopen in new window

transform-origin

transform: <变换原点x坐标> <变换原点y坐标> <变换原点z坐标>

变换原点 x 坐标

  • center:中间 默认值
  • left:最左边
  • right:最右边
  • 长度值:左边偏移
  • 百分值:左边偏移,相对于自身宽度

变换原点 y 坐标

  • center:中间 默认值
  • top:最上边
  • bottom:最下边
  • 长度值:上边偏移
  • 百分值:上边偏移,相对于自身高度

变换原点 z 坐标

长度值:上边偏移,0 默认值

perspective

perspective: <透视距离>

注意

perspective: 800px; 和 perspective-origin: center;作用在变换元素的父元素上,指距离父元素 800px 正对着透视原点位置透视到父元素上。

transform: perspective(800px); 作用在变换元素上,指距离父元素 800px 正对着当前元素的中心位置透视到父元素上。

建议不要使用 transform: perspective(),更不要2种透视方式同时用,很容易混乱。

perspective-origin

perspective: <透视原点x坐标> <透视原点y坐标>

透视原点 x 坐标

  • center:中间 默认值
  • left:最左边
  • right:最右边
  • left <长度值|百分值>:左边偏移
  • right <长度值|百分值>:右边偏移
  • 长度值:左边偏移
  • 百分值:左边偏移,相对于自身宽度

透视原点 y 坐标

  • center:中间 默认值
  • top:最上边
  • bottom:最下边
  • top <长度值|百分值>:上边偏移
  • bottom <长度值|百分值>:下边偏移
  • 长度值:上边偏移
  • 百分值:上边偏移,相对于自身高度

注意

透视原点 x 坐标 left <长度值|百分值> / right <长度值|百分值> 必须和 y 坐标 top <长度值|百分值> / bottom <长度值|百分值> 搭配使用,否则会无效。

过渡

transition-property

transition-property: none | <过渡作用属性>,#

  • all:全部属性 默认值
  • <property>:属性名

transition-duration

transition-duration: <过渡持续时间>,#

  • 时间值

transition-timing-function

transition-timing-function: <过渡缓动方式>,#

  • linear:匀速
  • ease:开始和结束慢 默认值
  • ease-in:开始慢
  • ease-out:结束慢
  • ease-in-out:开始和结束更慢
  • step-start:= steps(1, start)
  • step-end:= steps(1, end)
  • cubic-bezier() 函数
  • steps() 函数

transition-delay

transition-delay: <过渡延迟时间>,#

  • 时间值

transition

transition: [<transition-property> || <transition-duration> || <transition-timing-function> || <transition-delay>,]#

动画

animation-name

animation-name: none | <动画名>,#

  • 文本值
DETAILS

animation-duration

animation-duration: <动画持续时间>,#

  • 时间值:0s 默认值

animation-timing-function

transition-timing-function: <动画缓动方式>,#

  • linear:匀速
  • ease:开始和结束慢 默认值
  • ease-in:开始慢
  • ease-out:结束慢
  • ease-in-out:开始和结束更慢
  • step-start:= steps(1, start)
  • step-end:= steps(1, end)
  • cubic-bezier() 函数
  • steps() 函数

animation-delay

animation-delay: <动画延迟时间>,#

  • 时间值:0s 默认值

animation-iteration-count

animation-iteration-count: <动画播放次数>,#

  • 数值:1 默认值
  • infinite:无限

animation-direction

animation-direction: <动画方向>,#

  • normal:单向 默认值
  • alternate:双向

animation-fill-mode

animation-fill-mode: <填充模式>,#

  • none:无 默认值
  • forwards:动画结束后,保持结束关键帧的样式
  • backwards:动画开始前(存在延迟),保持开始关键帧的样式
  • both:forwards + backwards

animation-play-state

animation-play-state: <播放状态>,#

  • running:播放中 默认值
  • pause:暂停

animation

animation: [<animation-name> || <animation-duration> || <animation-timing-function> || <animation-delay> || <animation-iteration-count> || <animation-direction> || <animation-fill-mode> || <animation-play-state>,]#

滚动

scrollbar-gutter

scrollbar-gutter: <滚动条占位>

  • auto:自动,即滚动条存在时占位,否则不占位 默认值
  • stable:固定占位

overscroll-behavior-x

overscroll-behavior-x: <水平滚动至边界行为>

  • auto:自动 默认值
  • contain:阻止滚动冒泡
  • none:阻止滚动冒泡和默认行为

overscroll-behavior-y

overscroll-behavior-x: <垂直滚动至边界行为>

  • auto:自动 默认值
  • contain:阻止滚动冒泡
  • none:阻止滚动冒泡和默认行为

overscroll-behavior

overscroll-behavior: <overscroll-behavior-x> <overscroll-behavior-y>?

说明

<overscroll-behavior-y> 省略时值同 <overscroll-behavior-x>

-webkit-overflow-scrolling

-webkit-overflow-scrolling: <滚动效果>

  • auto:普通滚动,滑动结束时滚动立即停止
  • touch:惯性滚动,滑动结束时滚动逐渐减弱至停止

注意

据说是为了设置 IOS 的惯性滚动,但是实测无效,默认就是惯性滚动,猜测可能是新版的 IOS 不需要设置该属性了。

运动路径

offset-path

offset-path: <运动路径>

offset-rotate

offset-rotate: <运动角度>

  • auto:跟随运动路径朝向 默认值
  • 角度值

offset-distance

offset-distance: <运动距离>

offset

offset: <offset-path> [<offset-rotate> || <offset-distance>]?

Last Updated 12/4/2026, 10:28:57 AM