JavaScript实现全屏与退出全屏功能

js全屏与退出全屏

//全屏显式
        function showFull() {
            var full = document.getElementById("mapContainer");
            launchIntoFullscreen(full);
        }

        //退出全屏
        function delFull() {
            exitFullscreen();
        }

        //全屏显式
        function launchIntoFullscreen(element) {
            if (element.requestFullscreen) {
                element.requestFullscreen();
            }
            else if (element.mozRequestFullScreen) {
                element.mozRequestFullScreen();
            }
            else if (element.webkitRequestFullscreen) {
                element.webkitRequestFullscreen();
            }
            else if (element.msRequestFullscreen) {
                element.msRequestFullscreen();
            }
        }

        //退出全屏显式
        function exitFullscreen() {
            if (document.exitFullScreen) {
                document.exitFullScreen();
            } else if (document.mozCancelFullScreen) {
                document.mozCancelFullScreen();
            } else if (document.webkitExitFullscreen) {
                document.webkitExitFullscreen();
            } else if (document.msExitFullscreen) {
                document.msExitFullscreen();
            }
        }

参考:
https://www.jianshu.com/p/54729c73686a
https://www.cnblogs.com/s313139232/p/8371548.html
https://blog.csdn.net/ztsghjls/article/details/51788880

posted @ 2020-05-01 22:05  星空天宇  阅读(269)  评论(0编辑  收藏  举报