WeChat applet development documentation
/ 微信小程序API繪圖addColorStop(創(chuàng)建顏色漸變點(diǎn))
微信小程序API繪圖addColorStop(創(chuàng)建顏色漸變點(diǎn))
addColorStop
定義
創(chuàng)建一個(gè)顏色的漸變點(diǎn)。
Tip: 小于最小 stop 的部分會(huì)按最小 stop 的 color 來渲染,大于最大 stop 的部分會(huì)按最大 stop 的 color 來渲染。
Tip: 需要使用 addColorStop()
來指定漸變點(diǎn),至少要兩個(gè)。
參數(shù)
例子
const ctx = wx.crateCanvasContext('myCanvas')// Create circular gradientconst grd = ctx.createCircularGradient(75, 50, 50) 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')// Fill with gradientctx.setFillStyle(grd) ctx.fillRect(10, 10, 150, 80) ctx.draw()