如何使用HTML5的全屏API检查元素是否处于全屏状态 [英] How can I check if an element is in fullscreen with the fullscreen API for HTML5

查看:70
本文介绍了如何使用HTML5的全屏API检查元素是否处于全屏状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题中几乎是这个问题.我想返回一个值,该值告诉我所讨论的元素是否处于全屏模式.我该如何使用JavaScript?这似乎不起作用:

The question is pretty much in the title. I want to return a value that tells me whether or not the element in question is in fullscreen. How do I do that using javascript? This seems to not work:

function fs_status()
{
var fullscreenElement = canvas.fullscreenElement ||canvas.mozFullscreenElement || canvas.webkitFullscreenElement;
return fullscreenElement;
}

//对不起,我不太了解js.因此,如果您能举例说明,请使用画布"作为有问题的元素.

//Sorry, I don't really understand js. So if your making an example can you please use 'canvas' as the element in question.

推荐答案

在玩了一段时间后,我发现了如何做:

I found out how to do it after playing around a little:

function fs_status() {
    if (document.fullscreenElement || document.webkitFullscreenElement ||
        document.mozFullScreenElement)
            return 1;
    else
            return -1;
}

这篇关于如何使用HTML5的全屏API检查元素是否处于全屏状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆