HTML canvas fill() metode

Definering og brug

fill() Metoden fylder det aktuelle billede (stien). Standardfarven er sort.

Påmindelse:Brug fillStyle egenskab for at fylde en anden farve/gradient.

Note:Hvis stien ikke er lukket, så fill() Metoden tilføjer en linje mellem slut- og startpunktet på stien for at lukke stien, og fylder derefter stien.

Example

Draw a 150*100 pixel rectangle and then fill it with green:

Your browser does not support the HTML5 canvas tag.

JavaScript:

var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.rect(20,20,150,100);
ctx.fillStyle="green";
ctx.fill();

Try it yourself

Syntax

context.fill();

Browser support

The numbers in the table indicate the first browser version that fully supports this property.

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
4.0 9.0 3.6 4.0 10.1

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