html - 是否可以使用不适用于视频的 PIP 模式?

标签 html picture-in-picture

我想将一个 div 类显示为 PiP(画中画)。 我在谷歌上搜索了很多,但只是如何在视频中启用,而不是自定义 div。

在我的环境下,js、CSS、HTML都可以使用。我想使用 PiP 的 div 一秒一秒地变化。

最佳答案

不,画中画仅适用于

不过,您可以做的是在

const target = document.getElementById('target');
const source = document.createElement('canvas');
const ctx = source.getContext('2d');
ctx.font = "50px Arial";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
anim();

const stream = source.captureStream();
target.srcObject = stream;

const btn = document.getElementById('btn');
if( target.requestPictureInPicture ) {
  btn.onclick = e => target.requestPictureInPicture();
}
else {
  btn.disabled = true;
}

function anim() {
  ctx.fillStyle = "white";
  ctx.fillRect( 0, 0, source.width, source.height );
  ctx.fillStyle = "black";
  ctx.fillText( new Date().toTimeString().split(' ')[0], source.width / 2, source.height / 2 );
  requestAnimationFrame( anim );
}
<video id="target" controls muted autoplay></video>
<button id="btn">request PiP</button>

关于html - 是否可以使用不适用于视频的 PIP 模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61301087/

相关文章:

html - polymer - 主机的样式子节点

android - 如何在Android TV主屏幕上为当前正在运行的任务设置图标和标题

swift - iPhone Avplayer 中的 PIP 按钮

android - PiP进入时避免 Activity 娱乐

javascript - 引用错误: variable not defined

javascript - 如何将Json数据插入Html Div中?

javascript - 返回数据过滤器 onclick 可能吗?

ios - iPad画中画随机调用restoreUserInterfaceForPictureInPictureStopWithCompletionHandler

ios - 为什么画中画在iOS启动片刻后立即停止?

css - SPAN彼此相邻,没有 float