H5API:元素全屏(有兼容性)

本文介绍了HTML5中元素全屏、退出全屏的操作方法,包括使用element.requestFullScreen进入全屏,document.exitFullscreen退出全屏,以及通过document.fullScreen判断元素是否处于全屏状态。同时,提到了在IE浏览器中可能存在的兼容性问题。

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

1.元素进入全屏:

标准:元素.requestFullScreen

2.元素退出全屏:

标准:document.exitFullscreen    退出全屏 与元素无关  是document文档退出

3.元素是否全屏:

标准:document.fullScreen   这个好像非必要 ie没找到方法

4.全屏伪类选择器


<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style type="text/css">
		.box {
			width: 200px;
			height: 200px;
			background: green;
		}
		/*全屏伪类选择器*/
		.box:fullscreen {		/*标准写法*/
			background: blue;
		}
		.box:-webkit-full-screen, {		/*webkit内核 谷歌 Safari*/
			background: blue;
		}
		.box:-moz-full-screen {			/*moz内核 火狐*/
			background: blue;
		}
		.box:-ms-fullscreen {			/*ie浏览器*/
			background: blue;
		}



		
	</style>
	
</head>
<body>
	<div class="box">
		<input type='button' class='full' value='全屏' />
		<input type='button' class='cancelFull' value='取消全屏' />
		<input type='button' class='isFull' value='是
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值