JavaScript: FullScreen
<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> <meta name="apple-moible-web-app-capable" content="yes"> <meta name="apple-moible-web-app-status-bar-style" content="black"> <title>FullScreen</title> <meta content="font,孤僻字,如:叮𪠽,涂聚文,Geovin Du,塗聚文,geovindu,捷为工作室" name="keywords"> <meta content="font,孤僻字,涂聚文,Geovin Du,塗聚文,geovindu,捷为工作室" name="description"> <style> .box{ width: 200px; height: 200px; background-color: red; } </style> <script> // 进入全屏 https://developer.mozilla.org/en-US/docs/Web/API/Element/requestFullScreen //https://www.w3schools.com/jsref/met_element_requestfullscreen.asp const enterFullScreen = (el) => { if (el.requestFullscreen) { el.requestFullscreen(); } else if (el.mozRequestFullScreen) { el.mozRequestFullScreen(); } else if (el.webkitRequestFullscreen) { el.webkitRequestFullscreen(); } else if (el.msRequestFullscreen) { el.msRequestFullscreen(); } } // 退出全屏 const exitFullscreen = () => { if (document.exitFullscreen) { document.exitFullscreen(); } else if (document.webkitExitFullscreen) { document.webkitExitFullscreen(); } else if (document.mozCancelFullScreen) { document.mozCancelFullScreen(); } else if (document.msExitFullscreen) { document.msExitFullscreen(); } } // 当前处于全屏的元素 const fullscreenElement = () => { return document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement || null; } // 是否处于全屏 const isFullscreen = () => { return !!fullscreenElement() } // 切换 const toggleFullScreen = () => { isFullscreen()? exitFullscreen(): enterFullScreen(el); } </script> </head> <body> <div class="box" id="box"></div> <script> const el = document.getElementById('box'); el.onclick = toggleFullScreen; </script> </body> </html>
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)