我在我的页面上有一个画布,希望能切换它充满整个页面或返回原状态。我的页面通常比屏幕高,因此页面上会出现滚动条。当我在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
height: 100%; overflow:hidden
应用于 html 和 body 吗?在控制台中输入(function() { var s = document.createElement("style"); s.type = "text/css"; s.textContent = "html,body { height: 100%; overflow: hidden; }"; document.head.appendChild(s); })();
看起来可以解决这个问题。 - canon