HTML-canvas createRadialGradient() Methode
Voorbeeld
Teken een rechthoek en vul deze met een radiaal/cirkelvormig verloop:
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);
Browserondersteuning
De getallen in de tabel geven de eerste browserversie aan die de methode volledig ondersteunt.
Method | |||||
---|---|---|---|---|---|
createRadialGradient() | Yes | 9.0 | Yes | Yes | Yes |
Definitie en gebruik
De methode createRadialGradient() maakt een radiaal/cirkelvormig verloopobject.
Het verloop kan worden gebruikt om rechthoeken, cirkels, lijnen, tekst, enz.
Tip: Gebruik dit object als de waarde voor de strokeStyle- of fillStyle- eigenschappen.
Tip: gebruik de methode addColorStop() om verschillende kleuren op te geven en waar u de kleuren in het verloopobject wilt plaatsen.
JavaScript-syntaxis: | context .createRadialGradient( x0,y0,r0,x1,y1,r1 ); |
---|
Parameterwaarden
Parameter | Description |
---|---|
x0 | The x-coordinate of the starting circle of the gradient |
y0 | The y-coordinate of the starting circle of the gradient |
r0 | The radius of the starting circle |
x1 | The x-coordinate of the ending circle of the gradient |
y1 | The y-coordinate of the ending circle of the gradient |
r1 | The radius of the ending circle |
❮ HTML Canvas-referentie