canvasContext.createLinearGradient

解释:创建一个线性的渐变颜色。

参数:

参数名类型必填说明
x0Number起点的 x 坐标
y0Number起点的 y 坐标
x1Number阴影的模糊级别,数值越大越模糊
y1Number阴影的颜色

示例:

  1. const ctx = this.createCanvasContext('myCanvas');

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

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

图片