CanvasContext.addColorStop

2020-09-14 15:16 更新

簡(jiǎn)介

CanvasContext.addColorStop 是用于添加顏色的漸變點(diǎn)。

示例代碼

//.js
const ctx = my.createCanvasContext('canvas')


// 創(chuàng)建圓形梯度色
const grd = ctx.createLinearGradient(30, 10, 120, 10)
grd.addColorStop(0, 'red')
grd.addColorStop(0.16, 'orange')
grd.addColorStop(0.33, 'yellow')
grd.addColorStop(0.5, 'green')
grd.addColorStop(0.66, 'cyan')
grd.addColorStop(0.83, 'blue')
grd.addColorStop(1, 'purple')


// 填充梯度色
ctx.setFillStyle(grd)
ctx.fillRect(10, 10, 150, 80)
ctx.draw()

顯示效果如下圖所示:

漸變.png

入?yún)?/h4>

Object 類型,屬性如下:

屬性 類型 描述
stop Number 表示漸變中開始與結(jié)束之間的位置,范圍 0-1。
color Color 漸變點(diǎn)的顏色。

以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)