简体   繁体   English

为什么画布行为不正常?

[英]why canvas is not behaving properly?

I want CANVAS (gray part) to always cover the screen.我希望CANVAS (灰色部分)始终覆盖屏幕。
But it covers too much.但它涵盖的太多了。
What to do?该怎么办?
(I don't want to use CSS) (我不想使用 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>

You need to add display: block;您需要添加display: block; css to your canvas. CSS 到你的画布。

 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" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM