gpt4 book ai didi

JavaScript全屏无法滚动

转载 作者:行者123 更新时间:2023-12-05 00:40:01 26 4
gpt4 key购买 nike

我使用下面的脚本对页面进行了全屏切换,但是当页面全屏时出现问题,它无法向下滚动。我尝试为全屏添加 CSS overflow:scroll 但什么也没发生。

我希望有人可以帮助我解决这个问题。谢谢。

HTML:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="styles.css" rel="stylesheet" type="text/css">
<script src="script.js"></script>
</head>
<body>
<button id="btnScreen"><i class="icon-enlarge"></i></button>
<div style="height:1000px">Some Text</div>
</body>
</html>

JavaScript:

var goInFullscreen = function(element) {
if (element.requestFullscreen)
element.requestFullscreen();
else if (element.mozRequestFullScreen)
element.mozRequestFullScreen();
else if (element.webkitRequestFullscreen)
element.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
else if (element.msRequestFullscreen)
element.msRequestFullscreen();
}

var goOutFullscreen = function() {
if (document.exitFullscreen)
document.exitFullscreen();
else if (document.mozCancelFullScreen)
document.mozCancelFullScreen();
else if (document.webkitExitFullscreen)
document.webkitExitFullscreen();
else if (document.msExitFullscreen)
document.msExitFullscreen();
}

var isFullScreenCurrently = function() {
var full_screen_element = document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement || null;

if (full_screen_element === null)
return false;
else
return true;
}

var setBtnScreen = function() {
$("#btnScreen").on('click', function() {
if (isFullScreenCurrently()) {
goOutFullscreen();
$(this).find('i').removeClass('icon-shrink').addClass('icon-enlarge');
} else {
goInFullscreen($("body").get(0));
$(this).find('i').removeClass('icon-enlarge').addClass('icon-shrink');
}
});
}

CSS:

body:fullscreen
body:-ms-fullscreen,
body:-webkit-full-screen,
body:-moz-full-screen {
overflow: scroll !important;
}

最佳答案

您的 vendor 前缀必须在单独的 CSS 规则中(here's 讨论为什么会这样)

所以在你的情况下,正确的 CSS 应该是:

body:fullscreen {
overflow: scroll !important;
}
body:-ms-fullscreen {
overflow: scroll !important;
}
body:-webkit-full-screen {
overflow: scroll !important;
}
body:-moz-full-screen {
overflow: scroll !important;
}

关于JavaScript全屏无法滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51406630/

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