canvasContext.createLinearGradient
解释:创建一个线性的渐变颜色。
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
x0 | Number | 是 | 起点的 x 坐标 |
y0 | Number | 是 | 起点的 y 坐标 |
x1 | Number | 是 | 阴影的模糊级别,数值越大越模糊 |
y1 | Number | 是 | 阴影的颜色 |
示例:
- 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();