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

correct document picture-in-picture example #33293

Merged
merged 7 commits into from
May 8, 2024
Merged
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ page-type: guide

This guide provides a walkthrough of typical usage of the {{domxref("Document Picture-in-Picture API", "Document Picture-in-Picture API", "", "nocode")}}.

> **Note:** You can see the featured demo in action at [Document Picture-in-Picture API Example](https://mdn.github.io/dom-examples/document-picture-in-picture/) (see the full [source code](https://github.com/chrisdavidmills/dom-examples/tree/main/document-picture-in-picture) also).
> **Note:** You can see the featured demo in action at [Document Picture-in-Picture API Example](https://mdn.github.io/dom-examples/document-picture-in-picture/) (see the full [source code](https://github.com/mdn/dom-examples/tree/main/document-picture-in-picture) also).

## Sample HTML

Expand Down Expand Up @@ -72,22 +72,24 @@ The `width` and `height` options of `requestWindow()` set the Picture-in-Picture

```js
async function togglePictureInPicture() {
// Returns null if no pip window is currently open
if (!!window.documentPictureInPicture.window) {
// Open a Picture-in-Picture window.
const pipWindow = await documentPictureInPicture.requestWindow({
width: videoPlayer.clientWidth,
height: videoPlayer.clientHeight,
});
// Early return if there's already a Picture-in-Picture window open
if (window.documentPictureInPicture.window) {
joshfarrant marked this conversation as resolved.
Show resolved Hide resolved
return;
}

// Open a Picture-in-Picture window.
const pipWindow = await window.documentPictureInPicture.requestWindow({
width: videoPlayer.clientWidth,
height: videoPlayer.clientHeight,
});

// ...
// ...

// Move the player to the Picture-in-Picture window.
pipWindow.document.body.append(videoPlayer);
// Move the player to the Picture-in-Picture window.
pipWindow.document.body.append(videoPlayer);

// Display a message to say it has been moved
inPipMessage.style.display = "block";
}
// Display a message to say it has been moved
inPipMessage.style.display = "block";
}
```

Expand Down