我正在使用“fullscreenchange”事件来应用我想要的 css,方法是添加或删除一个 ID ( #showFullscreen
),该 ID () 将支配已经应用到的 css .fullscreen
。
var fullscreen = document.getElementsByClassName("fullscreen");
document.addEventListener("fullscreenchange", function() {
if (document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement) {
fullscreen[0].setAttribute("id", "showFullscreen");
} else if (!document.fullscreenElement || !document.webkitFullscreenElement || !document.mozFullScreenElement || !document.msFullscreenElement) {
fullscreen[0].removeAttribute("id", "showFullscreen");
}
});
如何使用 vanilla javascript 让此代码在所有浏览器中工作?