HTMLVideoElement: leavepictureinpicture event

leavepictureinpicture 事件会在 HTMLVideoElement 成功离开画中画模式时触发。

此事件不可取消,也不会冒泡。

语法

addEventListener()等方法中使用事件方法名,或者设置事件处理器属性。

addEventListener('leavepictureinpicture', event => { });

onleavepictureinpicture = event => { };

事件类型

事件属性

示例

这些示例为 leavepictureinpicture 事件增加事件侦听器, 然后在该事件处理程序对事件触发做出反应时发布消息。

使用 addEventListener():

const video = document.querySelector('#video');
const button = document.querySelector('#button');

function onExitPip() {
  console.log("Picture-in-Picture mode deactivated!");
}

video.addEventListener("leavepictureinpicture", onExitPip, false);

button.onclick = function() => {
  if (document.pictureInPictureElement) {
    document.exitPictureInPicture();
  }
}

使用事件处理程序 onleavepictureinpicture:

const video = document.querySelector('#video');
const button = document.querySelector('#button');

function onExitPip() {
  console.log("Picture-in-Picture mode deactivated!");
}

video.onleavepictureinpicture = onExitPip;

button.onclick = function() => {
  if (document.pictureInPictureElement) {
    document.exitPictureInPicture();
  }
}

规范

Specification
Picture-in-Picture
# eventdef-htmlvideoelement-leavepictureinpicture
Picture-in-Picture
# dom-htmlvideoelement-onleavepictureinpicture

浏览器兼容性

BCD tables only load in the browser

参见