3
我的代码是:我可以使用vh和vw指定画布尺寸吗?
var canvas = document.getElementById("canvas");
ctx = canvas.getContext("2d");
ctx.canvas.width = 40vw;
ctx.canvas.height = 40vh;
,它不工作。在JavaScript中设置画布尺寸时可以使用vw和vh吗?如果是这样,怎么样?
http://stackoverflow.com/questions/1664785/resize-html5-canvas-to-fit-window – andyderuyter
可能的重复你应该设置像素数量为'width'和'height'属性,其值为一个整数。然后,你可以用CSS来扭曲它。 – Oriol
@Oriol这只是延伸了我的形象。我该如何设置宽度和高度属性作为视口的比例? – Jonah