1 Star 0 Fork 0

math.most/html-css

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
007全屏.html 2.34 KB
一键复制 编辑 原始数据 按行查看 历史
math.most 提交于 2021-09-27 19:40 +08:00 . first commit
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>全屏</title>
</head>
<body>
<div>
<img src="./image/abc.jpg" alt="">
<input type="button" id="full" value="设置全屏">
<input type="button" id="cancelFull" value="退出全屏">
<input type="button" id="isFull" value="是否全屏">
</div>
<script>
/**
* 1. requestFullScreen 设置全屏
* 2. cancelFullScreen 退出全屏
* 3. fullScreenElement 是否全屏
*/
/**
* 不同浏览器需要加上前缀识别
* 1. 谷歌: webkitrequestFullScreen
* 2. 火狐: mozrequestFullScreen
* 3. ie: msrequestFullScreen
*/
window.onload = function () {
var div = document.querySelector("div");
document.querySelector("#full").onclick = function () {
if (div.requestFullScreen) {
div.requestFullScreen();
} else if (div.webkitRequestFullScreen) {
div.webkitRequestFullScreen();
} else if (div.mozRequestFullScreen) {
div.mozRequestFullScreen();
} else if (div.msRequestFullScreen) {
div.msRequestFullScreen();
}
}
document.querySelector("#cancelFull").onclick = function () {
if (document.cancelFullScreen) {
document.cancelFullScreen();
} else if (document.webkitCancelFullScreen) {
document.webkitCancelFullScreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.msCancelFullScreen) {
document.msCancelFullScreen();
}
}
document.querySelector("#isFull").onclick = function () {
if (document.fullScreenElement || document.webkitFullScreenElement || document.mozFullScreenElement || document.msFullScreenElement) {
alert(true);
} else {
alert(false);
}
}
}
</script>
</body>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/mathmost/html-css.git
git@gitee.com:mathmost/html-css.git
mathmost
html-css
html-css
master

搜索帮助