CanvasContext.createLinearGradient

2020-08-26 16:38 更新

解釋:創(chuàng)建一個(gè)線性的漸變顏色。

方法參數(shù)

參數(shù)名屬性必填默認(rèn)值說明

x0

Number

起點(diǎn)的 x 坐標(biāo)

y0

Number

起點(diǎn)的 y 坐標(biāo)

x1

Number

終點(diǎn)的 x 坐標(biāo)

y1

Number

終點(diǎn)的 y 坐標(biāo)

示例 

在開發(fā)者工具中打開


圖片示例

圖片

代碼示例

<canvas canvas-id="myCanvas" class="myCanvas" />

    Page({
        onLoad() {
            const canvasContext = swan.createCanvasContext('myCanvas');
    
            const grd = canvasContext.createLinearGradient(0, 0, 200, 0);
            grd.addColorStop(0, 'blue');
            grd.addColorStop(1, 'red');
    
            canvasContext.setFillStyle(grd);
            canvasContext.fillRect(30, 30, 150, 80);
            canvasContext.draw();
        }
    });


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

    掃描二維碼

    下載編程獅App

    公眾號
    微信公眾號

    編程獅公眾號