DOMPoint: fromPoint() static method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

Note: This feature is available in Web Workers.

The fromPoint() static method of the DOMPoint interface creates and returns a new mutable DOMPoint object given a source point.

You can also create a new DOMPoint object using the DOMPoint() constructor.

Although this interface is based on DOMPointReadOnly, it is not read-only; the properties within may be changed at will.

Syntax

js
DOMPoint.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 DOMPoint object whose coordinate and perspective values are identical to those in the source point. The point's properties are mutable and may be changed at any time.

Examples

Creating a mutable point from a read-only point

If you have a DOMPointReadOnly object, you can easily create a mutable copy of that point:

js
const mutablePoint = DOMPoint.fromPoint(readOnlyPoint);

Creating a 2D point

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

js
const center = DOMPoint.fromPoint({ x: 75, y: -50 });

Specifications

Specification
Geometry Interfaces Module Level 1
# dom-dompoint-frompoint

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
fromPoint() static method
Chrome – Full support
Chrome 61 (Release date: 2017-09-05)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 62 (Release date: 2018-09-05)
footnote Full support
Opera – Full support
Opera 48 (Release date: 2017-09-27)
footnote Full support
Safari – Full support
Safari 10.1 (Release date: 2017-03-27)
footnote Full support
Chrome Android – Full support
Chrome Android 61 (Release date: 2017-09-05)
footnote Full support
Firefox for Android – Full support
Firefox for Android 62 (Release date: 2018-09-05)
footnote Full support
Opera Android – Full support
Opera Android 45 (Release date: 2018-02-15)
footnote Full support
Safari on iOS – Full support
Safari on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
Samsung Internet – Full support
Samsung Internet 8 (Release date: 2018-07-18)
footnote Full support
WebView Android – Full support
WebView Android 61 (Release date: 2017-09-05)
footnote Full support
WebView on iOS – Full support
WebView on iOS 10.3 (Release date: 2017-03-27)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support