JavaScript: FullScreen

 

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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta name="apple-moible-web-app-capable" content="yes">
<meta name="apple-moible-web-app-status-bar-style" content="black">  
<title>FullScreen</title>
    <meta content="font,孤僻字,如:叮𪠽,涂聚文,Geovin Du,塗聚文,geovindu,捷为工作室" name="keywords">
<meta content="font,孤僻字,涂聚文,Geovin Du,塗聚文,geovindu,捷为工作室" name="description">
    <style>
    .box{
        width: 200px;
        height: 200px;
        background-color: red;
    }
    </style>
<script>
    // 进入全屏  https://developer.mozilla.org/en-US/docs/Web/API/Element/requestFullScreen
    //https://www.w3schools.com/jsref/met_element_requestfullscreen.asp
    const enterFullScreen = (el) => {
      if (el.requestFullscreen) {
        el.requestFullscreen();
      } else if (el.mozRequestFullScreen) {
        el.mozRequestFullScreen();
      } else if (el.webkitRequestFullscreen) {
        el.webkitRequestFullscreen();
      } else if (el.msRequestFullscreen) {
        el.msRequestFullscreen();
      }
    }
     
    // 退出全屏
    const exitFullscreen = () => {
      if (document.exitFullscreen) {
        document.exitFullscreen();
      } else if (document.webkitExitFullscreen) {
        document.webkitExitFullscreen();
      } else if (document.mozCancelFullScreen) {
        document.mozCancelFullScreen();
      } else if (document.msExitFullscreen) {
        document.msExitFullscreen();
      }
    }
     
    // 当前处于全屏的元素
    const fullscreenElement = () => {
      return document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement || null;
    }
     
     // 是否处于全屏
    const isFullscreen = () => {
      return !!fullscreenElement()
    }
     
     
     // 切换
    const toggleFullScreen = () => {
        isFullscreen()?
        exitFullscreen():
        enterFullScreen(el);
    }
     
    </script>
</head>
 
<body>
<div class="box" id="box"></div>
 
<script>
    const el = document.getElementById('box');
    el.onclick = toggleFullScreen;
</script>
</body>
</html>

  

posted @   ®Geovin Du Dream Park™  阅读(34)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
历史上的今天:
2023-04-29 cpp: Template Mothod Pattern
2023-04-29 mysql: character set in mysql 8.0
< 2025年3月 >
23 24 25 26 27 28 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 1 2 3 4 5
点击右上角即可分享
微信分享提示