画中画模式 documentPictureInPicture
画中画模式 即在当前网页再打开一个新的网页,这个网页可以悬浮在桌面上
api
documentPictureInPicture api 有兼容性,使用的时候要注意兼容性
创建窗口
- 创建使用的的api是documentPictureInPicture。requestWindow
- 创建的过程是异步的
// 获取将要放入 PiP 窗口的 DOM 元素
const pipContent = document.createElement("div");
// 请求创建一个 PiP 窗口
const pipWindow = await window.documentPictureInPicture.requestWindow({
width: 200, // 设置窗口的宽度
height: 300 // 设置窗口的高度
});
// 将原始元素添加到 PiP 窗口中
pipWindow.document.body.appendChild(pipContent);