HTML-Leinwand closePath () -Methode
Beispiele
Zeichnen Sie einen Pfad in der Form des Buchstabens L, und dann ziehen Sie eine Linie zum Ausgangspunkt zurückzukehren:
JavaScript:
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.beginPath();
ctx.moveTo(20,20);
ctx.lineTo(20,100);
ctx.lineTo(70,100);
ctx.closePath();
ctx.stroke();
var ctx=c.getContext("2d");
ctx.beginPath();
ctx.moveTo(20,20);
ctx.lineTo(20,100);
ctx.lineTo(70,100);
ctx.closePath();
ctx.stroke();
Versuchen »
Browser-Unterstützung
Internet Explorer 9, Firefox, Opera, Chrome und Safari Unterstützung closePath () -Methode.
Hinweis: 8 und frühere Versionen von Internet Explorer unterstützt nicht das <canvas> -Element.
Definition und Verwendung
closePath () -Methode einen Pfad vom aktuellen Punkt zum Ausgangspunkt zu schaffen.
Tipp: Verwenden Sie den Hub () Methode , um den genauen Pfad auf der Leinwand zu zeichnen.
Tipp: Verwenden Sie die fill () Methode um das Bild zu füllen (Standard ist schwarz). Verwenden Sie fillStyle Eigenschaft , um eine andere Farbe / Farbverlauf füllen.
JavaScript-Syntax: | Kontext .closePath (); |
---|
Weitere Beispiele
Beispiele
Da die Füllfarbe auf Rot:
JavaScript:
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.beginPath();
ctx.moveTo(20,20);
ctx.lineTo(20,100);
ctx.lineTo(70,100);
ctx.closePath();
ctx.stroke();
ctx.fillStyle="red";
ctx.fill();
var ctx=c.getContext("2d");
ctx.beginPath();
ctx.moveTo(20,20);
ctx.lineTo(20,100);
ctx.lineTo(70,100);
ctx.closePath();
ctx.stroke();
ctx.fillStyle="red";
ctx.fill();
Versuchen »