CanvasGradient

CanvasGradient interface represents an opaque object describing a gradient. It is returned by the methods CanvasRenderingContext2D.createLinearGradient() or CanvasRenderingContext2D.createRadialGradient() .

It can be used as a fillStyle or strokeStyle .

特性

As an opaque object, there is no exposed property.

方法

There is no inherited method.

CanvasGradient.addColorStop()
Adds a new stop, defined by an offset color , to the gradient. If the offset is not between 0 and 1 , inclusive, an INDEX_SIZE_ERR is raised; if the color can't be parsed as a CSS <color> SYNTAX_ERR 被引发。

规范

规范 状态 Comment
HTML Living Standard
The definition of 'CanvasGradient' in that specification.
实时标准

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
CanvasGradient Chrome 4 Edge 12 Firefox 3.6
3.6
Before Firefox 5.0, specifying non-finite values when adding color stops through a call to addColorStop() incorrectly throws SYNTAX_ERR instead of INDEX_SIZE_ERR .
IE 9 Opera 9 Safari 3.1 WebView Android Yes Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 3.2 Samsung Internet Android 1.0
addColorStop Chrome Yes Edge 12 Firefox 3.6 IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 4 Opera Android Yes Safari iOS Yes Samsung Internet Android Yes

图例

完整支持
完整支持
见实现注意事项。

另请参阅