本文主要是介绍js操作DOM切换全屏功能实现,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
不和你多BB,直接上代码。
function requestFullScreen (element) {//当前全屏状态let isFullSceen=document.isFullScreen || document.mozIsFullScreen || document.webkitIsFullScreen//多个游览器内核的全屏判断let requestMethod =element.requestFullScreen ||element.webkitRequestFullScreen ||element.mozRequestFullScreen ||element.msRequestFullScreenif (requestMethod) {if(isFullSceen){ //根据是否处于全屏状态 来进行切换 if (document.exitFullscreen) {document.exitFullscreen();}else if (document.mozCancelFullScreen) {document.mozCancelFullScreen();}else if (document.webkitCancelFullScreen) {document.webkitCancelFullScreen();}else if (document.msExitFullscreen) {document.msExitFullscreen();}if(typeof cfs != "undefined" && cfs) {cfs.call(el);}}else{requestMethod.call(element) //打开全屏}} else if (typeof window.ActiveXObject !== 'undefined') { //低版本的进入全屏和取消全屏都是这个方法var wscript = new ActiveXObject('WScript.Shell')if (wscript !== null) {wscript.SendKeys('{F11}')}}//返回操作后的全屏状态 return !isFullSceen
}
调用:
var elem = document.getElementById('domid')
let isFull=requestFullScreen(elem) //全屏切换 并且获取当前状态
这篇关于js操作DOM切换全屏功能实现的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!