画布基本功能——绘制矩形

fillRect:绘制并填充  strokeRect:绘制并描边  clearRect:擦除  都接受四个参数
(x: number, y: number, width: number, height: number)  canvas的起点是左上角,用法和position: relative差不多,后来居上
context.fillStyle = "rgba(0,0,255,0.6)" //通过rgba实现透明
context.fillRect(0, 0, 50, 50)
context.strokeStyle = "red"
context.strokeRect(50, 50, 20, 20)
context.clearRect(10, 10, 20, 20)  效果如下图

posted on 2022-03-15 20:44  In-6026  阅读(63)  评论(0)    收藏  举报

导航