Latest web development tutorials

HTML canvas createRadialGradient () method

HTML canvas Reference Manual HTML canvas Reference Manual

Examples

Draw a rectangle with a radial / circular gradient fill:

YourbrowserdoesnotsupporttheHTML5canvastag.

JavaScript:

var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");

var grd=ctx.createRadialGradient(75,50,5,90,60,100);
grd.addColorStop(0,"red");
grd.addColorStop(1,"white");

// Fill with gradient
ctx.fillStyle=grd;
ctx.fillRect(10,10,150,100);

try it"

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

Internet Explorer 9, Firefox, Opera, Chrome and Safari support createRadialGradient () method.

Note: 8 and earlier versions of Internet Explorer do not support the <canvas> element.


Definition and Usage

createRadialGradient () method creates a radial / circular gradient object.

Gradient can be used to fill rectangles, circles, lines, text, and so on.

Tip: Use this object as strokeStyle or fillStyle value of the property.

Tip: Use addColorStop () method specifies a different color, as well as where to locate the color gradient object.

JavaScript syntax: context .createRadialGradient (x0, y0, r0, x1, y1, r1);

Parameter Value

参数 描述
x0 渐变的开始圆的 x 坐标
y0 渐变的开始圆的 y 坐标
r0 开始圆的半径
x1 渐变的结束圆的 x 坐标
y1 渐变的结束圆的 y 坐标
r1 结束圆的半径


HTML canvas Reference Manual HTML canvas Reference Manual