全屏时,监听不到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
);
}