这个概念围绕了解画布的宽度。 您也需要确保您所有的画布资产 也使用计算方法 来在浏览器上发布信息。 我记录了我的代码, 我希望它有用,
<body>
// in style make your canvas 100% width and hight, this will not flex for all browsers sizes.
<style>
canvas{
width: 100%;
height:100%;
position: relative;
}
</style>
<canvas id="myCanvas"></canvas>
<script>
// here we are just getting the canvas and asigning it the to the vairable context
var canvas = document.getElementById( myCanvas );
var context = canvas.getContext( 2d );
// no we get with of content and asign the same hight as the with. this gives up aspect ration 1:1.
context.canvas.width = window.innerWidth;
context.canvas.height = window.innerWidth;
// If you want aspect ration 4:3 uncomment the line below.
//context.canvas.height = 3 * window.innerWidth / 4;
</script>
</body>