为什么 canvas 行为不正常?

why canvas is not behaving properly?

我想让CANVAS(灰色部分)一直遮住屏幕。
但是遮住太多了。
怎么办?
(我不想用CSS)

resize();

function resize() {
  document.getElementById("can").style.width = window.innerWidth + "px";
  document.getElementById("can").style.height = window.innerHeight + "px";
}
body {
  margin: 0;
  padding: 0;
}

#can {
  margin: 0;
  padding: 0;
  background-color: #eee;
}
<body onresize="resize();">
  <canvas id="can" />
</body>

您需要将 display: block; css 添加到您的 canvas。

resize();

function resize() {
  document.getElementById("can").style.width = window.innerWidth + "px";
  document.getElementById("can").style.height = window.innerHeight + "px";
}

window.addEventListener('resize', resize);
body {
  margin: 0;
  padding: 0;
}

#can {
  display: block;
  margin: 0;
  padding: 0;
  background-color: #eee;
}
<canvas id="can" />