我有一个按钮,我可以切换到全屏调用启动或取消全屏。当然,每次切换按钮时都必须更改按钮的外观。问题是,只要按下ESC键,按钮就不会更新。
document.addEventListener("keyup", function(e)
{
console.debug(e.keycode);
if (e.keyCode == 27)
{
btnFS.set("iconClass", "icon_FSlarge");
btnFS.set("label", "Set to Full Screen");
}
}, false);
我无法捕获按下的ESC键。 请指教。谢谢 克莱门特
答案 0 :(得分:3)
我找到了答案。解决方案是FullScreen API提供的FullScreenElement
var changeHandler = function() {
if(document.fullScreenElement||
document.webkitFullScreenElement||
document.mozFullScreenElement) {
alert("In fullscreen, I should do something here");
} else {
alert("NOT In fullscreen, I should do something here");
}
}
document.addEventListener("fullscreenchange", changeHandler, false);
document.addEventListener("webkitfullscreenchange", changeHandler, false);
document.addEventListener("mozfullscreenchange", changeHandler, false);
克莱门特
答案 1 :(得分:2)
这与其他答案类似,只是我修改了一些格式和拼写,以便它可以工作......
var changeHandler = function(){
if(document.fullscreenElement||document.webkitFullscreenElement||document.mozFullScreenElement){
alert("I am fullscreen now");
}else{
alert("No longer fullscreen..");
}
}
document.addEventListener("fullscreenchange", changeHandler, false);
document.addEventListener("webkitfullscreenchange", changeHandler, false);
document.addEventListener("mozfullscreenchange", changeHandler, false);