[英]Canvas toggle filling whole page removing scrollbar
我的页面上有一个画布,想要切换它以填充页面和向后。 我的页面通常“更高”然后是屏幕高度,因此页面上有一个滚动条。 当我像在CSS中那样设置画布的大小时,此滚动条不会隐藏:
canvas {
display: inline;
outline: 0;
margin: 50;
border: 1px solid #E0E0E0;
}
canvas.fullscreen {
display: block;
position: absolute;
top: 0;
left: 0;
border: none;
margin: 0;
}
我的JavaScript看起来像这样:
//toggle the fullscreen mode
function fullscreen() {
if (!fullWindowState) {
fullWindowState = true;
//canvas goes full Window
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
canvas.className = "fullscreen"
} else {
fullWindowState = false;
//canvas goes normal
canvas.width = 820;
canvas.height = 600;
canvas.className = "";
}
}
完整的代码也位于github上,页面位于gh-pages http://patsimm.github.io/mandelight/
当画布处于“全屏”模式时,我真的不知道如何删除滚动条。 每一个帮助都很感谢!
谢谢! patsimm
这与width <canvas>
标签有关。
如果未将<canvas>
设置为display:block
则会导致滚动条。
详细信息: http : //colla.me/bug/show/canvas_cannot_have_exact_size_to_fullscreen
当您处于fullWindowState
时,尝试将overflow
设置为hidden
;
//toggle the fullscreen mode
function fullscreen() {
if (!fullWindowState) {
fullWindowState = true;
//canvas goes full Window
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
canvas.className = "fullscreen"
document.body.scrollTop = 0; // <-- pull the page back up to the top
document.body.style.overflow = 'hidden'; // <-- relevant addition
} else {
fullWindowState = false;
//canvas goes normal
canvas.width = 820;
canvas.height = 600;
canvas.className = "";
document.body.style.overflow = 'visible'; // <-- toggle back to normal mode
}
}
对<html>
和<body>
标签使用以下CSS
样式,
<style>
html,
body {
margin: 0;
height: 100%;
overflow: hidden;
}
</style>
以及以下javascript
代码来设置<canvas id="canvas"><canvas>
元素的width
和height
,
<script>
var canvas = document.getElementById('canvas');
canvas.width = document.body.clientWidth;
canvas.height = document.body.clientHeight;
</script>
如果进入全屏模式并使用开发人员工具设置visibility: hidden
在画布上,则可以看到画布后面的页面内容太大,从而导致滚动条出现。 通过设置display: none
我可以摆脱滚动条display: none
页面页脚上display: none
。 在全屏模式下,您可以切换页脚或其他内容的display
属性,因为无论如何它都会被画布覆盖。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.