キャンバスの最大化
divで囲み、リサイズ時にdivのサイズに合わせる
code: html
<div id="wrapper">
<canvas id="canvas" width="" height=""></canvas>
</div>
code: css
display: block;
}
html,
body,
width: 100%;
height: 100%;
}
code: javascript
const toFullSizeCanvas = () => {
const canvas = document.querySelector('#canvas');
const wrapper = document.querySelector('#wrapper');
canvas.width = wrapper.offsetWidth;
canvas.height = wrapper.offsetHeight;
}
window.addEventListener("resize", () => {
toFullSizeCanvas();
});
window.addEventListener("load", () => {
toFullSizeCanvas();
})