<video src="a.mp4" muted autoplay></video> <a onclick="openFullscreen();">full</a> <script> var elem = document.getElementsByTagName("video")[0]; function openFullscreen() { if (elem.requestFullscreen) { elem.requestFullscreen().then(() => { //after fullscreen do someting }).catch((err) => { //alert(`Error attempting to enable fullscreen mode: ${err.message} (${err.name})`); }); } else if (elem.mozRequestFullScreen) { /* Firefox */ elem.mozRequestFullScreen(); } else if (elem.webkitRequestFullscreen) { /* Chrome, Safari and Opera */ elem.webkitRequestFullscreen(); } else if (elem.msRequestFullscreen) { /* IE/Edge */ elem.msRequestFullscreen(); } } // openFullscreen(); </script>
最后更新于 2022年10月13日
相关博文
js让页面某个元素全屏(比如视频)的方法