canvas的自适应问题

在vue项目中用了canvas的画圆,想要设置canvas自适应,后来了解到canvas不能够自适应,只能通过resize在屏幕宽度改变时去改变大小

var myCanvas = document.createElement("canvas");
myCanvas.setAttribute("width", screen.availWidth);
myCanvas.setAttribute("height", screen.availHeight);
myCanvas.setAttribute("id", "myCanvas");
document.body.appendChild(myCanvas);
window.addEventListener("resize", resizeCanvas, false);

function resizeCanvas() {
    w = canvas.width = window.innerWidth;
    h = canvas.height = window.innerHeight;
}

你可能感兴趣的:(HTML)