Skip to content

Commit

Permalink
Add event documentation on subpage
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofandel committed Jul 24, 2023
1 parent a6178bd commit 4781193
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
2 changes: 1 addition & 1 deletion files/en-us/_redirects.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9616,7 +9616,7 @@
/en-US/docs/Web/API/Screen.unlockOrientation /en-US/docs/Web/API/Screen/unlockOrientation
/en-US/docs/Web/API/Screen.width /en-US/docs/Web/API/Screen/width
/en-US/docs/Web/API/Screen/onorientationchange /en-US/docs/Web/API/Screen/orientationchange_event
/en-US/docs/Web/API/ScreenOrientation/onchange /en-US/docs/Web/API/ScreenOrientation#events
/en-US/docs/Web/API/ScreenOrientation/onchange /en-US/docs/Web/API/ScreenOrientation/change_event
/en-US/docs/Web/API/ScriptProcessorNode.bufferSize /en-US/docs/Web/API/ScriptProcessorNode/bufferSize
/en-US/docs/Web/API/ScriptProcessorNode.onaudioprocess /en-US/docs/Web/API/ScriptProcessorNode/audioprocess_event
/en-US/docs/Web/API/ScriptProcessorNode/audioprocess /en-US/docs/Web/API/ScriptProcessorNode/audioprocess_event
Expand Down
45 changes: 45 additions & 0 deletions files/en-us/web/api/screenorientation/change_event/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
title: "ScreenOrientation: change event"
short-title: change
slug: Web/API/ScreenOrientation/change_event
page-type: web-api-event
browser-compat: api.ScreenOrientation.change_event
---

{{securecontext_header}}{{APIRef("Idle Detection API")}}{{SeeCompatTable}}

The **`change`** event of the {{domxref("ScreenOrientation")}} fires when the orientation of the screen has changed, for example when a user rotates his mobile phone.

## Syntax

Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property.

```js
addEventListener("change", (event) => {});

onchange = (event) => {};
```

## Event type

A generic {{domxref("Event")}}.

## Example

In the following example, the `change` callback prints the status of `userState` and `screenState` to the console.

```js
screen.orientation.addEventListener("change", (event) => {
const type = event.target.type;
const angle = event.target.angle;
console.log(`ScreenOrientation change: ${type}, ${angle} degrees.`);
});
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}
14 changes: 13 additions & 1 deletion files/en-us/web/api/screenorientation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ A **`ScreenOrientation`** instance object can be retrieved using the {{domxref("

Listen to these events using `addEventListener()` or by assigning an event listener to the `oneventname` property of this interface.

- {{DOMxRef("ScreenOrientation.onchange", "change")}}
- {{DOMxRef("ScreenOrientation.change_event", "change")}}
- : The [event handler](/en-US/docs/Web/Events/Event_handlers) called whenever the screen changes orientation.

## Instance methods
Expand All @@ -34,6 +34,18 @@ Listen to these events using `addEventListener()` or by assigning an event liste
- {{DOMxRef("ScreenOrientation.unlock()")}}
- : Unlocks the orientation of the containing document from its default orientation.

## Example

In the following example, we listen for an {{DOMxRef("ScreenOrientation.change_event", "orientation change event")}} and log the new {{DOMxRef("ScreenOrientation.type", "screen orientation type")}} and {{DOMxRef("ScreenOrientation.angle")}}.

```js
screen.orientation.addEventListener("change", (event) => {
const type = event.target.type;
const angle = event.target.angle;
console.log(`ScreenOrientation change: ${type}, ${angle} degrees.`);
});
```

## Specifications

{{Specifications}}
Expand Down

0 comments on commit 4781193

Please sign in to comment.