微信小程序API 繪圖createLinearGradient(創(chuàng)建線性漸變)

2022-05-09 16:36 更新

微信小程序 canvas接口和方法繪圖接口和方法


canvasContext.createLinearGradient


定義

創(chuàng)建一個線性的漸變顏色。

Tip: 需要使用addColorStop()來指定漸變點,至少要兩個。

參數(shù)

參數(shù)類型定義
x0Number起點的x坐標
y0Number起點的y坐標
x1Number終點的x坐標
y1Number終點的y坐標

例子

const ctx = wx.createCanvasContext('myCanvas')

// Create linear gradient
const grd = ctx.createLinearGradient(0, 0, 200, 0)
grd.addColorStop(0, 'red')
grd.addColorStop(1, 'white')

// Fill with gradient
ctx.setFillStyle(grd)
ctx.fillRect(10, 10, 150, 80)
ctx.draw()


微信小程序 canvas接口和方法繪圖接口和方法

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

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號