DocumentPictureInPictureEvent
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
DocumentPictureInPictureEvent
接口是 Document Picture-in-Picture API 的 enter
事件(会在画中画窗口打开时触发)的对象。
构造函数
DocumentPictureInPictureEvent()
实验性-
创建一个新的
DocumentPictureInPictureEvent
对象实例。
实例属性
实例方法
继承其父接口 Event
的方法。
示例
js
documentPictureInPicture.addEventListener("enter", (event) => {
const pipWindow = event.window;
console.log("视频播放器已进入画中画窗口");
const pipMuteButton = pipWindow.document.createElement("button");
pipMuteButton.textContent = "静音";
pipMuteButton.addEventListener("click", () => {
const pipVideo = pipWindow.document.querySelector("#video");
if (!pipVideo.muted) {
pipVideo.muted = true;
pipMuteButton.textContent = "取消静音";
} else {
pipVideo.muted = false;
pipMuteButton.textContent = "静音";
}
});
pipWindow.document.body.append(pipMuteButton);
});
规范
Specification |
---|
Document Picture-in-Picture # documentpictureinpictureevent |
浏览器兼容性
BCD tables only load in the browser