其他分享
首页 > 其他分享> > js-点击全屏

js-点击全屏

作者:互联网

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button onclick="toggleFullScreen(event)">点我全屏</button>
    <script>
        function FullScreen(el) {
            var isFullscreen = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen;
            if (!isFullscreen) { //进入全屏,多重短路表达式
                (el.requestFullscreen && el.requestFullscreen()) ||
                    (el.mozRequestFullScreen && el.mozRequestFullScreen()) ||
                    (el.webkitRequestFullscreen && el.webkitRequestFullscreen()) || (el.msRequestFullscreen && el.msRequestFullscreen());

            } else { //退出全屏,三目运算符
                document.exitFullscreen ? document.exitFullscreen() :
                    document.mozCancelFullScreen ? document.mozCancelFullScreen() :
                        document.webkitExitFullscreen ? document.webkitExitFullscreen() : '';
            }
        }

        function toggleFullScreen(e) {
            var el = e.srcElement || e.target; //target兼容Firefox
            el.innerHTML == '点我全屏' ? el.innerHTML = '退出全屏' : el.innerHTML = '点我全屏';
            FullScreen(el);
        }
    </script>
</body>

</html>

标签:el,msRequestFullscreen,innerHTML,js,点击,全屏,&&,document
来源: https://blog.csdn.net/alo_ne/article/details/110421215