fullscreen.html
1.88 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Full screen</title>
<script src="../src/js/jquery-1.7.1.js"></script>
<style>
/* html */
:-webkit-full-screen html{
width: 100%;
height: 100%;
}
:-moz-fullscreen html{
width: 100%;
height: 100%;
}
:fullscreen html{
width: 100%;
height: 100%;
}
#myfull {
width: 100%;
height: 100%;
}
</style>
</head>
<div id="myfull">
<h1>Hello word</h1>
<button class="full">全屏显示</button>
<button class="backfull">退出全屏</button>
</div>
<body>
<script>
$(function(){
// 找到支持的方法, 使用需要全屏的 element 调用
function launchFullScreen(element) {
if (element.requestFullscreen) {
element.requestFullscreen();
} else if (element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if (element.webkitRequestFullscreen) {
element.webkitRequestFullscreen();
} else if (element.msRequestFullscreen) {
element.msRequestFullscreen();
}
}
$('.full').click(function(){
// launchFullScreen(document.documentElement);
launchFullScreen(document.getElementById("myfull"));
})
$('.backfull').click(function(){
exitFullscreen();
})
function exitFullscreen() {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.mozExitFullScreen) {
document.mozExitFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
}
}
// 在支持全屏的浏览器中启动全屏
// 整个页面
// 某个元素
// launchFullScreen(document.getElementById("videoElement"));
})
</script>
</body>
</html>