大网数据广告活动
Web 标准与前端开发

DOMMatrix: translateSelf() method

· 52CE 我爱测

The `translateSelf()` method of the DOMMatrix interface is a mutable transformation method that modifies a matrix. It applies the specified vectors and returns the updated matrix. The default vector is `[0, 0, 0]`.

Geometry Interfaces

The translateSelf() method of the DOMMatrix interface is a mutable transformation method that modifies a matrix. It applies the specified vectors and returns the updated matrix. The default vector is [0, 0, 0].

To translate a matrix without mutating it, see DOMMatrixReadOnly.translate()

Syntax

translateSelf(translateX, translateY)
translateSelf(translateX, translateY, translateZ)

Parameters

  • translateX
    • : A number representing the abscissa (x-coordinate) of the translating vector.
  • translateY
    • : A number representing the ordinate (y-coordinate) of the translating vector.
  • translateZ
    • : A number representing the z component of the translating vector. If not supplied, this defaults to 0. If this is anything other than 0, the resulting matrix will be 3D.

Return value

Returns itself; the DOMMatrix translated by the given vector.

Examples

const matrix = new DOMMatrix(); // create a matrix
console.log(matrix.toString()); // output: "matrix(1, 0, 0, 1, 0, 0)"
matrix.translateSelf(25, 25); // mutate it
console.log(matrix); // output: "matrix(1, 0, 0, 1, 25, 25)"

Specifications

Browser compatibility

See also

  • DOMMatrixReadOnly.translate()
  • CSS transform property
  • CSS translate property
  • CSS transform-function functions
    • transform-function/translate
    • transform-function/translate3d
    • transform-function/translateX
    • transform-function/translateY
    • transform-function/translateZ
  • CSS transforms module
  • SVG transform attribute
  • CanvasRenderingContext2D interface methods
    • CanvasRenderingContext2D.translate()
    • CanvasRenderingContext2D.transform()
    • CanvasRenderingContext2D.setTransform()
    • CanvasRenderingContext2D.resetTransform()

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。