W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
CanvasContext.createLinearGradient 用于創(chuàng)建一個線性的漸變色。需要使用 addColorStop()
來指定漸變點,至少需要兩個漸變點。
//.js
const ctx = my.createCanvasContext('canvas')
const grd = ctx.createLinearGradient(10, 10, 150, 10)
grd.addColorStop(0, 'yellow')
grd.addColorStop(1, 'blue')
ctx.setFillStyle(grd)
ctx.fillRect(20, 20, 250, 180)
ctx.draw()
顯示效果如下圖所示:
Object 類型,屬性如下:
屬性 | 類型 | 描述 |
---|---|---|
x0 | Number | 起點 x 坐標(biāo)。 |
y0 | Number | 起點 y 坐標(biāo)。 |
x1 | Number | 終點 x 坐標(biāo)。 |
y1 | Number | 終點 y 坐標(biāo)。 |
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: