Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New page: DOMMatrixReadOnly.flipY() #37171

Merged
merged 7 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions files/en-us/web/api/dommatrixreadonly/flipx/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ browser-compat: api.DOMMatrixReadOnly.flipX

{{APIRef("Geometry Interfaces")}}{{AvailableInWorkers}}

The `flipX()` method of the {{domxref("DOMMatrixReadOnly")}} interface creates a new matrix being the result of the original matrix flipped about the x-axis.
The **`flipX()`** method of the {{domxref("DOMMatrixReadOnly")}} interface creates a new matrix being the result of the original matrix flipped about the x-axis. This is equivalent to multiplying the matrix by `DOMMatrix(-1, 0, 0, 1, 0, 0)`. The original matrix is not modified.

## Syntax

Expand All @@ -18,16 +18,14 @@ The `flipX()` method of the {{domxref("DOMMatrixReadOnly")}} interface creates a

### Return value

Returns a [`DOMMatrix`](/en-US/docs/Web/API/DOMMatrix) containing a new matrix being the result of the original matrix flipped about the x-axis, which is equivalent to multiplying the matrix by `DOMMatrix(-1, 0, 0, 1, 0, 0)`. The original matrix is not modified.
Returns a [`DOMMatrix`](/en-US/docs/Web/API/DOMMatrix).

## Examples

### Inverting a triangle

In this example, the SVG contains two paths in the shape of a triangle, both drawn to the same position. Note that the x co-ordinate of the viewBox attribute is negative, showing us content from both sides of the x-axis.

The JavaScript first creates an identity matrix, then uses the `flipX()` method to create a new matrix, which is then applied to the blue triangle, inverting it across the x-axis. The red triangle is left in place.

#### HTML

```html
Expand All @@ -39,6 +37,8 @@ The JavaScript first creates an identity matrix, then uses the `flipX()` method

#### JavaScript

The JavaScript first creates an identity matrix, then uses the `flipX()` method to create a new matrix, which is then applied to the blue triangle, inverting it across the x-axis. The red triangle is left in place.

```js
const flipped = document.getElementById("flipped");
const matrix = new DOMMatrixReadOnly();
Expand All @@ -57,3 +57,7 @@ flipped.setAttribute("transform", flippedMatrix.toString());
## Browser compatibility

{{Compat}}

## See also

- {{domxref("DOMMatrixReadOnly.flipY()")}}
63 changes: 63 additions & 0 deletions files/en-us/web/api/dommatrixreadonly/flipy/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
title: "DOMMatrixReadOnly: flipY() method"
short-title: flipY()
slug: Web/API/DOMMatrixReadOnly/flipY
page-type: web-api-instance-method
browser-compat: api.DOMMatrixReadOnly.flipY
---

{{APIRef("Geometry Interfaces")}}{{AvailableInWorkers}}

The **`flipY()`** method of the {{domxref("DOMMatrixReadOnly")}} interface creates a new matrix being the result of the original matrix flipped about the y-axis. This is equivalent to multiplying the matrix by `DOMMatrix(1, 0, 0, -1, 0, 0)`. The original matrix is not modified.

## Syntax

```js-nolint
DOMMatrixReadOnly.flipY()
```

### Return value

A [`DOMMatrix`](/en-US/docs/Web/API/DOMMatrix).

## Examples

### Inverting a triangle

In this example, the SVG contains two identical [paths](/en-US/docs/Web/SVG/Attribute/d) in the shape of a triangle; they are both drawn to have the same size and position. The viewbox has a negative y value showing us content from both sides of the y-axis. This enables the flipped triangle to be withing the viewport after it is transformed.

#### HTML

```html
<svg height="200" width="100" viewBox="0 -100 100 200">
<path fill="red" d="M 0 0 L 100 0 L 50 100 Z" />
<path fill="blue" d="M 0 0 L 100 0 L 50 100 Z" id="flipped" />
</svg>
```

#### JavaScript

The JavaScript creates an [identity matrix](/en-US/docs/Web/API/DOMMatrixReadOnly/isIdentity), then uses the `flipY()` method to create a new matrix, which is then applied to the blue triangle, inverting it across the y-axis. The red triangle is left in place.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this doc coming soon? Currently broken link

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's in another PR


```js
const flipped = document.getElementById("flipped");
const matrix = new DOMMatrix();
const flippedMatrix = matrix.flipY();
flipped.setAttribute("transform", flippedMatrix.toString());
```

#### Result

{{EmbedLiveSample('Inverting a triangle')}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal, but there's a vertical scrollbar here.

estelle marked this conversation as resolved.
Show resolved Hide resolved

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- {{domxref("DOMMatrixReadOnly.flipX()")}}
Loading