html video 视频 退出画中画事件 leavepictureinpicture event
source link: https://blog.p2hp.com/archives/9094
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
The leavepictureinpicture
event is fired when the HTMLVideoElement
leaves picture-in-picture mode successfully.
This event is not cancelable and does not bubble.
Syntax
Use the event name in methods like addEventListener()
, or set an event handler property.
addEventListener('leavepictureinpicture', event => { });
onleavepictureinpicture = event => { };
Event properties
This interface also inherits properties from its parent Event
.
Examples
These examples add an event listener for the HTMLVideoElement's leavepictureinpicture
event, then post a message when that event handler has reacted to the event firing.
Using 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();
}
}
Using the onleavepictureinpicture
event handler property:
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();
}
}
via https://developer.mozilla.org/en-US/docs/Web/API/HTMLVideoElement/leavepictureinpicture_event
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK