我在获取窗口大小时遇到问题,我尝试以下代码:
Javascript
var game;
function game() {
this.canvas = document.getElementById('canvas');
this.canvasWidth = window.innerWidth;
this.canvasHeight = window.innerHeight;
this.initCanvas = function() {
this.canvas.style.width = this.canvasWidth + "px";
this.canvas.style.height = this.canvasHeight + "px";
}
this.run = function() {
this.initCanvas();
}
}
game = new game();
game.run();
我也有
CSS
html, body {
padding: 0;
margin: 0;
}
我的身体里只有一块帆布。
问题是,我有一个垂直和水平滚动条。这意味着画布的尺寸太大。如何在不出现滚动条的情况下使其成为窗口大小?