渐变对象。
CanvasGradient.addColorStop(number stop, string color)
添加颜色的渐变点。小于最小stop的部分会按最小stop的color来渲染,大于最大stop的部分会按最大stop的color来渲染。
起始版本: 1.0.0
参数:
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| stop | number | 是 | 表示渐变中开始与结束之间的位置,范围0 ~ 1。 |
| color | string | 是 | 渐变点的颜色。 |
示例:
const ctx = has.createCanvasContext('myCanvas');
// Create linear gradient
const grd = ctx.createLinearGradient(30, 10, 120, 10);
grd.addColorStop(0, 'red');
grd.addColorStop(0.2, 'white');
grd.addColorStop(0.4, 'blue');
grd.addColorStop(0.6, 'gray');
grd.addColorStop(0.8, 'green');
grd.addColorStop(1, 'black');
// Fill with gradient
ctx.setFillStyle(grd);
ctx.fillRect(10, 10, 150, 80);
ctx.draw();