English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
createRadialGradient() is a Canvas 2The D API determines the coordinates of two circles based on parameters to draw a radial gradient. This method returns CanvasGradient.
Draw a rectangle and fill it with a radial/Circular gradient fill:
<!DOCTYPE html> <html> <head> <title>HTML canvas createRadialGradient() method usage (Basic Tutorial Website oldtoolbag.com)</<title> </<head> <body> <canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3> Your browser does not support HTML5 canvas tag. </canvas> <script> 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"); ctx.fillStyle=grd; ctx.fillRect(10,10,150,100); </script> </body> </html>Test and see ‹/›
IEFirefoxOperaChromeSafari
Internet Explorer 9Firefox, Opera, Chrome, and Safari support createRadialGradient() method.
Note:Internet Explorer 8 and earlier versions do not support the <canvas> element.
The createRadialGradient() method creates a radial/Circular Gradient Object.
Gradients can be used to fill rectangles, circles, lines, text, and more
Tip:Please use the object asstrokeStyle or fillStyle the value of the property.
Tip:Please use addColorStop() The method specifies different colors and where to locate colors in the gradient object.
JavaScript Syntax: | context.createRadialGradient(x0,y0,r0,x1,y1,r1); |
---|
Parameter | Description |
---|---|
x0 | X coordinate of the starting circle in the gradient |
y0 | Y coordinate of the starting circle in the gradient |
r0 | Radius of the starting circle |
x1 | X coordinate of the ending circle in the gradient |
y1 | Y coordinate of the ending circle in the gradient |
r1 | Radius of the ending circle |