学习如何通过使用 stroke() 或 fill() 方法在画布上实际地绘制矩形。绘制成功后图片如下。
<canvas width="300" height="300" id="canvas"/>
<script>
// 0. 获取到页面上的 canvas 标签元素节点
const canvasEle = document.querySelector('#canvas')
// 1. 获取当前这个画布的工具箱
const ctx = canvasEle.getContext('2d')
// 红色矩形
ctx.beginPath();
ctx.lineWidth="6";
ctx.strokeStyle="red";
ctx.rect(5,5,290,140);
ctx.stroke();
// 绿色矩形
ctx.beginPath();
ctx.lineWidth="4";
ctx.strokeStyle="green";
ctx.rect(30,30,50,50);
ctx.stroke();
// 蓝色矩形
ctx.beginPath();
ctx.lineWidth="10";
ctx.strokeStyle="blue";
ctx.rect(50,50,150,80);
ctx.stroke();
</script>
《一品江山》短片剧高清在线免费观看:https://www.jgz518.com/xingkong/26586.html
《帕丁顿熊国语》喜剧片高清在线免费观看:https://www.jgz518.com/xingkong/56193.html
《边走边唱》记录片高清在线免费观看:https://www.jgz518.com/xingkong/29087.html
《杀不死》国产剧高清在线免费观看:https://www.jgz518.com/xingkong/40845.html
独家揭秘:力量至强单职业传奇私服,畅玩新体验,不容错过!:https://501h.com/jingpin/2024-08-26/30721.html