W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
CanvasContext.beginPath 是開始創(chuàng)建一個路徑,需要調(diào)用 fill
或者 stroke
才會使用路徑進行填充或描邊。 在創(chuàng)建路徑最開始時,相當于調(diào)用了一次 beginPath()
,同一個路徑內(nèi)的多次 setFillStyle()
、setStrokeStyle()
、setLineWidth()
等設置,以最后一次設置為準。
//.js
const ctx = my.createCanvasContext('canvas')
ctx.rect(20, 20, 150, 50)
ctx.setFillStyle('blue')
ctx.fill();
ctx.beginPath();
ctx.rect(20, 50, 150, 40)
ctx.setFillStyle('yellow')
ctx.fillRect(20, 170, 150, 40)
ctx.rect(10, 100, 100, 30)
ctx.setFillStyle('red')
ctx.fill()
ctx.draw()
顯示效果如下圖所示:
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: