如何检测何时发生FullScreen事件,请按f11键。如果它发生意味着,屏幕处于全屏模式然后显示警告。不使用键码比较.Plz给我一个不同的方法来做到这一点。
// mozilla proposal
element.requestFullScreen();
document.cancelFullScreen();
// Webkit (works in Safari and Chrome Canary)
element.webkitRequestFullScreen();
document.webkitCancelFullScreen();
// Firefox (works in nightly)
element.mozRequestFullScreen();
document.mozCancelFullScreen();
// W3C Proposal
element.requestFullscreen();
document.exitFullscreen();
或
element.addEventListener('fullscreeneventchange', function(e) {
if (document.fullScreen) {
/* make it look good for fullscreen */
} else {
/* return to the normal state in page */
}
}, true);
答案 0 :(得分:0)
window.onresize = function (event) {
var maxHeight = window.screen.height,
maxWidth = window.screen.width,
curHeight = window.innerHeight,
curWidth = window.innerWidth;
if (maxWidth == curWidth && maxHeight == curHeight) {
// do something
}
}
或者,您也可以尝试使用window.screen.availWidth& window.screen.availHeight(请注意,这些可能实际上不是屏幕分辨率,但允许使用菜单栏/浏览器窗口尺寸的宽度等。)
答案 1 :(得分:0)
如果您想在 F11 按键检查全屏,请尝试以下小提琴:
function checkWH(){
if((window.outerWidth-screen.width) ==0 && (window.outerHeight-screen.height) ==0 )
{
alert('fullscreen');
}
}
$(window).keypress(function(event){
var code = event.keyCode || event.which;
if(code == 122){
setTimeout(function(){checkWH();},1000);
}
});