通过jquery监听div双击全屏再次双击恢复demo

$(".Box").on("dblclick", function(){
            var docId=$(this).attr("id");
            var height=document.getElementById(docId);
            var fullscreenElement =
                document.fullscreenElement ||
                document.mozFullScreenElement ||
                document.webkitFullscreenElement;
            
            console.log(fullscreenElement);
             if(docId&&fullscreenElement==null){
                launchIntoFullscreen(height);
            }else{
                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();
                }
            }
$(".Box").on("dblclick", function(){
            var docId=$(this).attr("id");
            var height=document.getElementById(docId);
            var fullscreenElement =
                document.fullscreenElement ||
                document.mozFullScreenElement ||
                document.webkitFullscreenElement;
            
            console.log(fullscreenElement);
             if(docId&&fullscreenElement==null){
                launchIntoFullscreen(height);
            }else{
                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();
                }
            }

posted @ 2021-04-17 14:37  逝年的我们  阅读(275)  评论(0编辑  收藏  举报