监听ESC退出全屏事件

  • Post author:
  • Post category:其他


全屏时,监听不到ESC退出全屏事件时可以试试这个方法:

// 绑定监听事件
fullListen() {
    let screen = document.getElementById("screen");
    if (screen.requestFullscreen) {
        document.addEventListener("fullscreenchange", () => {
            if (getFullscreenElement() == null) {
                console.log('exit')
            else {
                console.log('full')
            }
        }
    }
}

// 获取全屏状态
getFullscreenElement = () => {
    return (
        document['fullscreenElement'] ||
        document['mozFullScreenElement'] ||
        document['msFullScreenElement'] ||
        document['webkitFullscreenElement'] || null
    );
}



版权声明:本文为Ariel_tilamisu原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。