DocumentPictureInPicture:进入事件
当画中画窗口成功打开时,DocumentPictureInPicture
接口的 enter
事件将被触发。
语法
在像 addEventListener()
这样的方法中使用事件名称,或者设置事件处理程序属性。
js
addEventListener("enter", (event) => {});
onenter = (event) => {};
事件类型
示例
js
documentPictureInPicture.addEventListener("enter", (event) => {
const pipWindow = event.window;
console.log("Video player has entered the pip window");
const pipMuteButton = pipWindow.document.createElement("button");
pipMuteButton.textContent = "Mute";
pipMuteButton.addEventListener("click", () => {
const pipVideo = pipWindow.document.querySelector("#video");
if (!pipVideo.muted) {
pipVideo.muted = true;
pipMuteButton.textContent = "Unmute";
} else {
pipVideo.muted = false;
pipMuteButton.textContent = "Mute";
}
});
pipWindow.document.body.append(pipMuteButton);
});
规范
规范 |
---|
Document Picture-in-Picture # dom-documentpictureinpicture-onenter |
浏览器兼容性
BCD 表格仅在浏览器中加载