-
Notifications
You must be signed in to change notification settings - Fork 1
/
fullscreen.html
66 lines (66 loc) · 2.16 KB
/
fullscreen.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>FullScreen API 测试</title>
<link rel="stylesheet" type="text/css" href="style.css">
<style>
.div {
background-color: DeepSkyBlue;
height: 20em;
width:100%;
}
:fullscreen {
height: 100%;
width: 100%;
}
:-moz-full-screen {
height: 100%;
width: 100%;
}
:-ms-fullscreen {
height: 100%;
width: 100%
}
:-webkit-full-screen {
height: 100%;
width: 100%
}
</style>
</head>
<body>
<div id="div" class="div" onclick="toggleFullScreen()"></div>
<button onclick="toggleFullScreen()">进入全屏模式</button>
<script>
function toggleFullScreen() {
if (document.fullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement) {
if (document.exitFullscreen) {
document.exitFullscreen();
}
else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
}
else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
}
else {
alert("当前浏览器不支持全屏显示,请切换浏览器再打开");
}
} else {
if (document.createElement("div").requestFullscreen) {
document.getElementById("div").requestFullscreen();
}
else if (document.createElement("div").mozRequestFullScreen) {
document.getElementById("div").mozRequestFullScreen();
}
else if (document.createElement("div").webkitRequestFullscreen) {
document.getElementById("div").webkitRequestFullscreen();
}
else {
alert("当前浏览器不支持全屏显示,请切换浏览器再打开");
}
}
}
</script>
</body>
</html>