html实现iframe全屏

前言

html浏览器全屏操作,基于jquery

iframe全屏、指定标签全屏

实现

css

css 复制代码
/** 全屏*/
.lay-dbclick-box{
	position: relative;
	width: 100%;
    height: 100%;
}
.lay-dbclick-screen{
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
    height: 100%;
    z-index: 99999999999999;
}
.lay-fullScreen{
	position: fixed;
    left: 0;
    top: 0;
    border-radius: 0;
    padding: 0;
    margin: 0;
    width: 100%;
    height: 100%;
    z-index: 9999999999999;
}

html

关键是lay-dbclick-box和lay-dbclick-screen,其中的iframe是内容

html 复制代码
<div class="lay-dbclick-box">
	<iframe src="" width="100%" height="100%" id="fullb" frameborder="0" allowfullscreen="" ></iframe>
	<div class="lay-dbclick-screen"></div>
</div>

js

javascript 复制代码
openFullScreen();

/**
 * -------------------------------------------------------------------------------------------------------
 * 通用全屏操作
 */
function openFullScreen(){
	// 双击全屏/退出全屏
	$(".lay-dbclick-screen").dblclick(function(){
		var val = $(this).parent().attr("lay-svalue");
		if(!val){
			$(this).parent().addClass("lay-fullScreen");
			$(this).parent().attr("lay-svalue", 1);
			fullScreen();
		}else{
			$(this).parent().removeClass("lay-fullScreen");
			$(this).parent().attr("lay-svalue", "");
			exitFullscreen();
		}
	})
	// 全屏事件监听
	document.addEventListener("fullscreenchange", function(){
        if (getFullscreenElement() == null) {
        	console.log("-----------------[退出全屏]--------------")
           $(".lay-fullScreen").attr("lay-svalue", "");
			$(".lay-fullScreen").removeClass("lay-fullScreen");
			exitFullscreen();
        }else {
            console.log("-----------------[打开全屏]--------------")
        }
    })
}

/**
 * -------------------------------------------------------------------------------------------------------
 * 获取全屏状态
 */
function getFullscreenElement(){
    return (
        document['fullscreenElement'] ||
        document['mozFullScreenElement'] ||
        document['msFullScreenElement'] ||
        document['webkitFullscreenElement'] || null
    );
}

/**
 * -------------------------------------------------------------------------------------------------------
 * 全屏
 */
function fullScreen() {
    var element = document.documentElement;
    if (element.requestFullscreen) {
        element.requestFullscreen();
    } else if (element.msRequestFullscreen) {
        element.msRequestFullscreen();
    } else if (element.mozRequestFullScreen) {
        element.mozRequestFullScreen();
    } else if (element.webkitRequestFullscreen) {
        element.webkitRequestFullscreen();
    }
}

/**
 * --------------------------------------------------------------------------------------------------------
 * 退出全屏
 */
function exitFullscreen() {
    if (document.exitFullscreen) {
        document.exitFullscreen();
    } else if (document.msExitFullscreen) {
        document.msExitFullscreen();
    } else if (document.mozCancelFullScreen) {
        document.mozCancelFullScreen();
    } else if (document.webkitExitFullscreen) {
        document.webkitExitFullscreen();
    }
}
相关推荐
NiceCloud喜云36 分钟前
Opus 4.8 的 Effort Control 怎么选:Low 到 Max 五档策略
android·java·大数据·前端·c++·python·spring
wordbaby1 小时前
React Native + RNOH:跨页面数据回传的最佳实践与避坑指南
前端·react native
GISer_Jing1 小时前
Three.js着色器编译机制深度解析
javascript·webgl·着色器
丷丩1 小时前
MapLibre GL JS第22课:查看本地GeoJSON
前端·javascript·map·mapbox·maplibre gl js
油炸自行车1 小时前
Claude Code 错误:API Error: 400 Failed to deserialize the JSON body into the
开发语言·javascript·json·trae·claude code·api error 400
Front思2 小时前
AI前端工程师需要具备能力+
前端·人工智能·ai
ZC跨境爬虫4 小时前
跟着 MDN 学CSS day_29:(掌握文本与字体样式的核心艺术)
前端·css·ui·html·tensorflow
李子琪。5 小时前
网络空间安全深度实战:CSRF 漏洞原理剖析与基于 Token 的纵深防御体系构建(全栈实验报告)
前端·安全·csrf
冰暮流星5 小时前
javascript之history对象介绍
前端·笔记
IT_陈寒5 小时前
Vite热更新失灵?你可能漏了这个配置
前端·人工智能·后端