我对javascript非常陌生,只了解基本知识。我有一个HTML复选框,该复选框由javascript驱动,可以切换和取消切换全屏。我面临的问题是我不知道如何做到这一点,因此,如果有人在使用Escape或F11切换全屏后退出了全屏,我该如何做,因此该复选框会自动取消选中。请提供确切的脚本<3。
这是我到目前为止的内容:https://codepen.io/SkylixMC/pen/JmJwVL
我尝试使用此脚本没有成功:
var el = document.getElementById('fullscreen');
if (el.checked == true){
document.onfullscreenchange = function ( event ) {
el.checked = false;
};
}) );
答案 0 :(得分:1)
花了我比我想象的更长的时间。 在this之后,我可以得出以下结论:
elem.addEventListener("mozfullscreenchange",function(){
if (document.mozFullScreen == false) {
document.getElementById("fullscreen").checked = false;
}
}, false);
elem.addEventListener("webkitfullscreenchange",function(){
if (document.webkitIsFullScreen == false) {
document.getElementById("fullscreen").checked = false;
}
}, false);
答案 1 :(得分:0)
let fullScreen = false
window.onkeydown = e =>{
if(fullScreen & e.keyCode==122 || e.keyCode==27){
//here you clear stuff , couse user wants to exit
console.log("exitFullScreen")
fullScreen = false
}
}
window.onresize = _=> {if((screen.availHeight-70 || screen.height-70) <= window.innerHeight && "fullscreen"){
fullScreen = true
console.log("enteringFullScreen")
}}