Appearance
@jtopo/core / LinearGradient
Class: LinearGradient
线性渐变
js
let rg = new LinearGradient(0,0, 20, 20);
rg.addColorStop(0, 'white');
rg.addColorStop(0.5, 'red');
rg.addColorStop(1, 'blue');
// 也可以一次性设置:
rg.setColors([[0, 'white'], [0.5, 'red'], [1, 'blue']]);Hierarchy
StyleGradient↳
LinearGradient
Implements
CanvasGradient
Table of contents
Constructors
Properties
Methods
Constructors
constructor
new LinearGradient(startX, startY, stopX, stopY)
Parameters
| Name | Type |
|---|---|
startX | number |
startY | number |
stopX | number |
stopY | number |
Overrides
StyleGradient.constructor
Properties
className
className: string
colors
colors: [number, string][]
颜色列表 例如: [[0, 'white'], [1, 'blue']]
例如:[[0, 'white'], [0.5, 'red'], [1, 'blue']]
Inherited from
StyleGradient.colors
dirty
dirty: boolean = true
Inherited from
StyleGradient.dirty
startX
startX: number = 0
开始坐标x
startY
startY: number = 0
结束坐标y
stopX
stopX: number = 0
结束坐标x
stopY
stopY: number = 0
结束坐标y
Methods
addColorStop
addColorStop(offset, color): void
添加颜色停靠点到颜色列表中。
Parameters
| Name | Type | Description |
|---|---|---|
offset | number | 颜色停靠点的偏移量,通常是一个0到1之间的数值,表示在渐变中的位置。 |
color | string | 颜色的表示,可以是CSS颜色字符串,如「rgb」或「#rrggbb」格式。 |
Returns
void
Implementation of
CanvasGradient.addColorStop
setColors
setColors(colors): void
设置颜色并更新状态
Parameters
| Name | Type | Description |
|---|---|---|
colors | [number, string][] | {Array} 颜色数组,用于更新当前对象的颜色 |
Returns
void
toJSON
toJSON(): Object
Returns
Object
Inherited from
StyleGradient.toJSON
update
update(): void
Returns
void
Inherited from
StyleGradient.update