<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>初探canvas绘图</title>
<style>
#test{
background-color: antiquewhite;
}
</style>
</head>
<body>
<canvas id="test" width="800" height="900"></canvas>
<script>
/** @type {HTMLCanvasElement} */
//获取画布
const cvs = document.getElementById("test");
//覆盖html中设置的长宽
cvs.width=350;
cvs.height = 150;
//获取画笔
const ctx = cvs.getContext("2d");
//勾画矩形框,并使用颜色填充矩形框
ctx.fillStyle="red";
ctx.fillRect(
20,20,
200,100
)
</script>
</body>
</html>