HTML - doekvulStyleiendom
Voorbeeld
Definieer 'n rooi vulkleur vir die reghoek:
JavaScript:
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.fillStyle = "#FF0000";
ctx.fillRect(20, 20, 150, 100);
Blaaierondersteuning
Die nommers in die tabel spesifiseer die eerste blaaierweergawe wat die metode ten volle ondersteun.
Method | |||||
---|---|---|---|---|---|
fillStyle() | Yes | 9.0 | Yes | Yes | Yes |
Definisie en gebruik
Die fillStyle-eienskap stel of gee die kleur, gradiënt of patroon terug wat gebruik is om die tekening te vul.
Standaard waarde: | #000000 |
---|---|
JavaScript-sintaksis: | konteks .fillStyle= kleur | gradiënt | patroon ; |
Eiendomswaardes
Value | Description | Play it |
---|---|---|
color | A CSS color value that indicates the fill color of the drawing. Default value is #000000 | |
gradient | A gradient object (linear or radial) used to fill the drawing | |
pattern | A pattern object to use to fill the drawing |
Meer voorbeelde
Voorbeeld
Definieer 'n gradiënt (van bo na onder) as die vulstyl vir die reghoek:
JavaScript:
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var my_gradient = ctx.createLinearGradient(0, 0, 0, 170);
my_gradient.addColorStop(0, "black");
my_gradient.addColorStop(1, "white");
ctx.fillStyle = my_gradient;
ctx.fillRect(20, 20, 150, 100);
Voorbeeld
Definieer 'n gradiënt (van links na regs) as die vulstyl vir die reghoek:
JavaScript:
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var my_gradient=ctx.createLinearGradient(0, 0, 170, 0);
my_gradient.addColorStop(0, "black");
my_gradient.addColorStop(1, "white");
ctx.fillStyle = my_gradient;
ctx.fillRect(20, 20, 150, 100);
Voorbeeld
Definieer 'n gradiënt wat gaan van swart, na rooi, na wit, as die vulstyl vir die reghoek:
JavaScript:
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var my_gradient=ctx.createLinearGradient(0, 0, 170, 0);
my_gradient.addColorStop(0, "black");
my_gradient.addColorStop(0.5, "red");
my_gradient.addColorStop(1, "white");
ctx.fillStyle = my_gradient;
ctx.fillRect(20, 20, 150, 100);
Prent om te gebruik:
Voorbeeld
Gebruik 'n prent om die tekening te vul:
JavaScript:
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var img = document.getElementById("lamp");
var pat = ctx.createPattern(img, "repeat");
ctx.rect(0, 0, 150, 100);
ctx.fillStyle = pat;
ctx.fill();
❮ HTML-doekverwysing