safari html5 自动全屏,html - Safari html5 video fullscreen size - Stack Overflow

本文介绍了如何使用CSS的webkit-full-screen属性为视频创建全屏功能,并提供自定义控制器。通过将视频和控制面板放入一个div容器中,然后应用全屏样式。同时,针对Safari浏览器可能出现的问题,提供了修复CSS样式。此外,还通过jQuery和JavaScript代码展示了全屏API的使用,以实现全屏的进入和退出操作。文章最后提到了如何添加画中画功能的相关资源链接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

As @Jack say we need to use the CSS -webkit-full-screen

I think you wanna have you're own customized controller right? In that case, we need to put the control panel and the video inside a div, and use the full-screen on that. Let's us just call it videoContainer

First we make the HTML

Your browser does not support the video tag.

CSS

.videoContainer:fullscreen, .videoContainer:-ms-fullscreen, .videoContainer:-moz-full-screen, .videoContainer:-webkit-full-screen {

width: 100%;

height: 100%;

}

Sometimes it can be buggy (bug in Safari) so a way to fix that is to add a style to the default control.

video:-webkit-full-screen::-webkit-media-controls-panel, video:-webkit-full-screen::-webkit-media-controls, video:-webkit-full-screen::-webkit-media-text-track-container {

display: none !important;

opacity: 0;

}

This will style Safari's normal controllers, and make sure they don't show and make it's kinda awkward.

So long so good. All we need now to get the controller to work. This can be done by a little jQuery/Javascript code by using the fullscreen API

$(".fullscreen").click(function(){

if (document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement) {

// exit full-screen

if (document.exitFullscreen) {

document.exitFullscreen();

} else if (document.webkitExitFullscreen) {

document.webkitExitFullscreen();

} else if (document.mozCancelFullScreen) {

document.mozCancelFullScreen();

} else if (document.msExitFullscreen) {

document.msExitFullscreen();

}

}else if (document.fullscreenEnabled || document.webkitFullscreenEnabled || document.mozFullScreenEnabled || document.msFullscreenEnabled) {

var i = $("#videoContainer");

// go full-screen

if (i.requestFullscreen) {

i.requestFullscreen();

} else if (i.webkitRequestFullscreen) {

i.webkitRequestFullscreen();

} else if (i.mozRequestFullScreen) {

i.mozRequestFullScreen();

} else if (i.msRequestFullscreen) {

i.msRequestFullscreen();

}

}

});

If you wanna know how to add Picture In Picture you can see this post here

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值