调整HTML 5画布的大小以适应窗口如何自动缩放HTML 5?<canvas>元素以适应页面?例如,我可以得到一个<div>若要通过设置height和width属性为100%,但<canvas>不会扩大,对吧?
3 回答
不负相思意
TA贡献1777条经验 获得超10个赞
JavaScript
/* important! for alignment, you should make things * relative to the canvas' current width/height. */function draw() { var ctx = (a canvas context); ctx.canvas.width = window.innerWidth; ctx.canvas.height = window.innerHeight; //...drawing code...}
CSS
html, body { width: 100%; height: 100%; margin: 0;}
添加回答
举报
0/150
提交
取消