gpt4 book ai didi

javascript - Animate CC HTML5 - 切换全屏

转载 作者:行者123 更新时间:2023-12-03 01:35:50 25 4
gpt4 key购买 nike

我在按钮上放置了这段代码(如下),以强制我的 HTML5 游戏全屏显示,但我想让它也通过该按钮返回 - 目前它只能使用 ESC 键。有可能吗?

this.fsbtn.addEventListener("click", doFullscreen);

function doFullscreen() {
var i;
var elem = document.getElementById("animation_container");
var fs = ["requestFullscreen", "webkitRequestFullscreen", "mozRequestFullScreen", "msRequestFullscreen"];

for (i = 0; i < 4; i++) {
if (elem[fs[i]]) {
elem[fs[i]]();
break;
}
}
}

最佳答案

当然有可能。将您的 doFullscreen 函数更改为 toggle one检查它是否全屏:

function toggleFullscreen(event) {
var element = document.body;

if (event instanceof HTMLElement) {
element = event;
}

var isFullscreen = document.webkitIsFullScreen || document.mozFullScreen || false;

element.requestFullScreen = element.requestFullScreen || element.webkitRequestFullScreen || element.mozRequestFullScreen || function () {
return false;
};
document.cancelFullScreen = document.cancelFullScreen || document.webkitCancelFullScreen || document.mozCancelFullScreen || function () {
return false;
};

isFullscreen ? document.cancelFullScreen() : element.requestFullScreen();
}

关于javascript - Animate CC HTML5 - 切换全屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51080798/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com