-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqp.html
66 lines (63 loc) · 1.64 KB
/
qp.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>qp</title>
</head>
<body>
<div style="margin:0 auto;height:600px;width:700px;">
<div id="content" style="margin:0 auto;height:500px;width:700px; background:#ccc;" >
<button id="btn">全屏</button>
<h1>全屏展示和退出全屏</h1>
<button id="btnn" >退出</button>
</div>
</div>
<script>
document.getElementById("btn").onclick=function(){
var elem = document.getElementById("content");
requestFullScreen(elem);
/*
注意这里的样式的设置表示全屏显示之后的样式,
退出全屏后样式还在,
若要回到原来样式,需在退出全屏里把样式还原回去
*/
elem.style.height = '800px';
elem.style.width = '1000px';
};
document.getElementById("btnn").onclick=function () {
exitFullscreen();
};
/*
全屏显示
*/
function requestFullScreen(element) {
debugger
var requestMethod = element.requestFullScreen || element.webkitRequestFullScreen || element.mozRequestFullScreen || element.msRequestFullScreen;
requestMethod.call(element);
};
/*
全屏退出
*/
function exitFullscreen() {
var elem = document;
var elemd = document.getElementById("content");
if (elem.webkitCancelFullScreen) {
elem.webkitCancelFullScreen();
} else if (elem.mozCancelFullScreen) {
elemd.mozCancelFullScreen();
} else if (elem.cancelFullScreen) {
elem.cancelFullScreen();
} else if (elem.exitFullscreen) {
elem.exitFullscreen();
} else {
//浏览器不支持全屏API或已被禁用
};
/*
退出全屏后样式还原
*/
elemd.style.height = '500px';
elemd.style.width = '700px'
}
</script>
</body>
</html>