js点击按钮模拟F11全屏

2024-03-11  本文已影响0人  甘道夫老矣
  // 点击全屏
    handleFullScreen(): void {
        if (this.isFullScreen) {
            // 取消全屏
            let el: any = document;
            if (el.exitFullscreen) {
                document.exitFullscreen()
            } else if (el.webkitCancelFullScreen) {
                el.webkitCancelFullScreen()
            } else if (el.mozCancelFullScreen) {
                el.mozCancelFullScreen()
            } else if (el.msExitFulldcreen) {
                el.msExitFulldcreen()
            }
            this.isFullScreen = false
        } else {
            // 全屏
            let element: any = document.documentElement
            if (element.requestFullscreen) {
                element.requestFullscreen()
            } else if (element.webkitRequestFullScreen) {
                element.webkitRequestFullScreen()
            } else if (element.mozRequestFullScreen) {
                element.mozRequestFullScreen()
            } else if (element.msRequestFulldcreen) {
                element.msRequestFulldcreen()
            }
            this.isFullScreen = true
        }
    }

上一篇下一篇

猜你喜欢

热点阅读