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

DOMPointReadOnly: fromPoint() static method

· 52CE 我爱测

The static **DOMPointReadOnly** method `fromPoint()` creates and returns a new `DOMPointReadOnly` object given a source point.

Geometry Interfaces

The static DOMPointReadOnly method fromPoint() creates and returns a new DOMPointReadOnly object given a source point.

You can also create a new DOMPointReadOnly object using the DOMPointReadOnly.DOMPointReadOnly constructor.

Syntax

DOMPointReadOnly.fromPoint(sourcePoint)

Parameters

  • sourcePoint
    • : A DOMPoint or DOMPointReadOnly instance, or an object containing the following properties, from which to take the values of the new point's properties:
      • x
        • : An unrestricted floating-point value indicating the x-coordinate of the point in space. This is generally the horizontal coordinate, with positive values being to the right and negative values to the left. The default value is 0.
      • y
        • : An unrestricted floating-point number providing the point's y-coordinate. This is the vertical coordinate, and barring any transforms applied to the coordinate system, positive values are downward and negative values upward toward the top of the screen. The default is 0.
      • z
        • : An unrestricted floating-point value which gives the point's z-coordinate, which is (assuming no transformations that alter the situation) the depth coordinate; positive values are closer to the user and negative values retreat back into the screen. The default value is 0.
      • w
        • : The point's w perspective value, given as an unrestricted floating-point number. The default is 1.

Return value

A new DOMPointReadOnly object (which is identical to the source point).

Examples

Creating a 2D point

This sample creates a 2D point, specifying an inline object that includes the values to use for DOMPointReadOnly.x and DOMPointReadOnly.y. The z and w properties are allowed to keep their default values (0 and 1 respectively).

const point2D = DOMPointReadOnly.fromPoint({ x: 25, y: 25 });

Creating a 3D point using an existing point

This example creates a point, origPoint, of type DOMPoint, using DOMPoint.DOMPoint. That point is then used as the input for fromPoint() to create a new point, newPoint.

const origPoint = new DOMPoint(25, 25, 100, 0.5);

const newPoint = DOMPointReadOnly.fromPoint(origPoint);

Specifications

Browser compatibility

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

资料来源与适用范围

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

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

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