H5视频画中画功能
一个H5视频,可以从浏览器独立出来播放视频,看起来像是一个本地应用。画中画功能是chrome70+的新功能
<video id="video" src="https://example.com/file.mp4"></video>
<button id="togglePipButton"></button>
<script>
const video = document.getElementById('video');
const togglePipButton = document.getElementById('togglePipButton');
// Hide button if Picture-in-Picture is not supported or disabled.
togglePipButton.hidden = !document.pictureInPictureEnabled ||
video.disablePictureInPicture;
togglePipButton.addEventListener('click', function() {
// If there is no element in Picture-in-Picture yet, let’s request
// Picture-in-Picture for the video, otherwise leave it.
if (!document.pictureInPictureElement) {
video.requestPictureInPicture()
.catch(error => {
// Video failed to enter Picture-in-Picture mode.
});
} else {
document.exitPictureInPicture()
.catch(error => {
// Video failed to leave Picture-in-Picture mode.
});
}
});
</script>
常见问题FAQ
- 免费下载或者VIP会员专享资源能否直接商用?
- 提示下载完但解压或打开不了?
- 找不到素材资源介绍文章里的示例图片??
- 钛宇宙
0条评论