1

我有一个按钮,我可以切换到调用启动全屏或取消全屏。当然,每次切换按钮时,按钮都必须随着按钮外观的变化而更新。问题是,只要按下 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 键。请指教。谢谢克莱门特

4

2 回答 2

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);

克莱门特

于 2013-08-16T10:09:22.083 回答
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);
于 2014-02-08T19:05:17.600 回答