首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

translate3d()

translate3d() CSS函数在三维空间中重新定位一个元素。

这种转换的特点是三维矢量。其坐标定义元素在每个方向上的移动量。

语法

代码语言:javascript
复制
translate3d(tx, ty, tz)

可能值

tx——表示平移矢量的横坐标的<length>值。

ty——表示平移向量的纵坐标的<length>值。

tz——表示平移矢量的z分量的<length>值。

它们不能是<percentage>值; 在这种情况下,包含该变换的属性被认为是无效的。

Cartesian coordinates on ℝ2

Homogeneous coordinates on ℝℙ2

Cartesian coordinates on ℝ3

Homogeneous coordinates on ℝℙ3

This transform applies to the 3D space and cannot be represented on the plane.

A translation is not a linear transform in ℝ3 and cannot be represented using a matrix in the Cartesian coordinates system.

100tx010ty001tz0001

实例

使用单轴转换

HTML

代码语言:javascript
复制
<div>Static</div>
<div class="moved">Moved</div>
<div>Static</div>

CSS

代码语言:javascript
复制
div {
  width: 60px;
  height: 60px;
  background-color: skyblue;
}

.moved {
  /* Equivalent to perspective(500px) translateX(10px) */
  transform: perspective(500px) translate3d(10px, 0, 0px);
  background-color: pink;
}

结果

结合z轴和x轴平移

HTML

代码语言:javascript
复制
<div>Static</div>
<div class="moved">Moved</div>
<div>Static</div>

CSS

代码语言:javascript
复制
div {
  width: 60px;
  height: 60px;
  background-color: skyblue;
}

.moved {
  transform: perspective(500px) translate3d(10px, 0, 100px);
  background-color: pink;
}

结果

另见

  • transform
  • <transform-function>

扫码关注腾讯云开发者

领取腾讯云代金券