new Gradient()
Gradient class
梯度类
- Source:
- Tutorials:
- See:
-
- fabric.Gradient#initialize for constructor definition
Members
gradientTransform :Array.<Number>
A transform matrix to apply to the gradient before painting.
Imported from svg gradients, is not applied with the current transform in the center.
Before this transform is applied, the origin point is at the top left corner of the object
plus the addition of offsetY and offsetX.
在绘制前应用于渐变的变换矩阵。
从svg渐变导入,不应用于中心的当前变换。
在应用此转换之前,原点位于对象的左上角
加上offsetty和offsetX。
Type:
- Array.<Number>
gradientUnits :String
coordinates units for coords.
If `pixels`, the number of coords are in the same unit of width / height.
If set as `percentage` the coords are still a number, but 1 means 100% of width
for the X and 100% of the height for the y. It can be bigger than 1 and negative.
allowed values pixels or percentage.
坐标单位表示坐标。
如果是' pixels ',则以相同的宽度/高度为单位的线数。
如果设置为“百分比”,则坐标仍然是一个数字,但1表示宽度的100%
X的高度和y的高度的100%它可以大于1并且是负的。
允许的值像素或百分比。
Type:
- String
offsetX :Number
Horizontal offset for aligning gradients coming from SVG when outside pathgroups
水平偏移量用于在外部路径组时对齐来自SVG的梯度
Type:
- Number
offsetY :Number
Vertical offset for aligning gradients coming from SVG when outside pathgroups
垂直偏移量用于在外部路径组时对齐来自SVG的梯度
Type:
- Number
type :String
Gradient type linear or radial
梯度型线性或径向
Type:
- String
Methods
(static) fromElement(el, instance, opacityAttr, svgOptions, viewBoxWidth, viewBoxHeight, width, height) → {fabric.Gradient}
Returns fabric.Gradient instance from an SVG element
返回织物。来自SVG元素的渐变实例
Parameters:
Name | Type | Description |
---|---|---|
el |
SVGGradientElement | SVG gradient elementSVG渐变元素 |
instance |
fabric.Object | |
opacityAttr |
String | A fill-opacity or stroke-opacity attribute to multiply to each stop's opacity.填充不透明度或描边不透明度属性,以乘以每个图层的不透明度。 |
svgOptions |
Object | an object containing the size of the SVG in order to parse correctly gradients that uses gradientUnits as 'userSpaceOnUse' and percentages.一个包含SVG大小的对象,以便正确解析渐变 它使用gradientUnits作为userSpaceOnUse和百分比。 |
viewBoxWidth |
Object.number | width part of the viewBox attribute on svgsvg上viewBox属性的width部分 |
viewBoxHeight |
Object.number | height part of the viewBox attribute on svgsvg的viewBox属性的高度部分 |
width |
Object.number | width part of the svg tag if viewBox is not specified如果未指定viewBox,则使用svg标签的width部分 |
height |
Object.number | height part of the svg tag if viewBox is not specified如果未指定viewBox,则使用svg标签的height部分 |
- Source:
- See:
Returns:
Gradient instance
- Type
- fabric.Gradient
addColorStop(colorStop) → {fabric.Gradient}
Adds another colorStop
添加另一个颜色
Parameters:
Name | Type | Description |
---|---|---|
colorStop |
Object | Object with offset and color带有偏移和颜色的对象 |
Returns:
thisArg
- Type
- fabric.Gradient
initialize(options) → {fabric.Gradient}
Constructor
构造函数
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object | Options object with type, coords, gradientUnits and colorStops
Properties
|
Returns:
thisArg
- Type
- fabric.Gradient
toLive(ctx) → {CanvasGradient}
Returns an instance of CanvasGradient
返回CanvasGradient的实例
Parameters:
Name | Type | Description |
---|---|---|
ctx |
CanvasRenderingContext2D | Context to render on要渲染的上下文 |
Returns:
- Type
- CanvasGradient
toObject(propertiesToIncludeopt) → {Object}
Returns object representation of a gradient
返回渐变的对象表示形式
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
propertiesToInclude |
Array |
<optional> |
Any properties that you might want to additionally include in the output您可能希望在输出中额外包含的任何属性 |
Returns:
- Type
- Object
toSVG(object) → {String}
Returns SVG representation of an gradient
返回渐变的SVG表示形式
Parameters:
Name | Type | Description |
---|---|---|
object |
Object | Object to create a gradient for对象,为其创建渐变 |
Returns:
SVG representation of an gradient (linear/radial)
- Type
- String