onfullscreenchange DOM事件 [英] onfullscreenchange DOM event
问题描述
如标题所示,我想知道当浏览器进入/离开全屏模式时,触发事件的最可靠方式是什么。
as the title reads, I'd like to know what is the most reliable way to trigger an event when the Browser(s) enters/leaves in/out the fullscreen mode.
注意:我不是问如何全屏当前页面,我只是想知道是否有一种方法来排队一些任务,如果用户,例如,按F11或任何其他相关的全屏输入键。
note : I'm not asking how to fullscreen the current page, I just want to know whether or not there is a way to queue some tasks if the user, for example, press F11 or any other related fullscreen-entering keys.
推荐答案
screen.width
和 screen.height
告诉用户的屏幕分辨率,所以请尝试:
screen.width
and screen.height
tell you the user's screen resolution, so try this:
var fullscreen;
function onfullscreenchange(full) {
...
}
// You might want to use addEventListener and its equivalents instead
window.onresize = function () {
if (window.outerWidth === screen.width && window.outerHeight === screen.height) {
if (!fullscreen) {
fullscreen = true;
onfullscreenchange(true);
}
} else {
if (fullscreen) {
fullscreen = false;
onfullscreenchange(false);
}
};
我知道这不是最干净或最强壮的所有这一切的方式,但希望它给你一个想法。值得注意的是,IE< 9需要一种不同的方法来确定窗口大小,所以我会让你去看看。
I'm aware this isn't the cleanest or most robust way of doing all this, but hopefully it gives you an idea. Notably, IE<9 needs a different approach for determining the window size, so I'll leave you to look that up.
这篇关于onfullscreenchange DOM事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!