HTML-Leinwand globalAlpha Eigentum
Beispiele
Zeichnen Sie zunächst ein rotes Rechteck, und dann wird die Transparenz (globalAlpha) auf 0,5, und dann ein blaues und ein grünes Rechteck zu zeichnen:
JavaScript:
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.fillStyle="red";
ctx.fillRect(20,20,75,50);
// Turn transparency on
ctx.globalAlpha=0.2;
ctx.fillStyle="blue";
ctx.fillRect(50,50,75,50);
ctx.fillStyle="green";
ctx.fillRect(80,80,75,50);
var ctx=c.getContext("2d");
ctx.fillStyle="red";
ctx.fillRect(20,20,75,50);
// Turn transparency on
ctx.globalAlpha=0.2;
ctx.fillStyle="blue";
ctx.fillRect(50,50,75,50);
ctx.fillStyle="green";
ctx.fillRect(80,80,75,50);
Versuchen »
Browser-Unterstützung
Internet Explorer 9, Firefox, Opera, Chrome und Safari unterstützen globalAlpha Eigenschaft.
Hinweis: 8 und frühere Versionen von Internet Explorer unterstützt nicht das <canvas> -Element.
Definition und Verwendung
globalAlpha Eigenschaft legt liefert die aktuelle Zeichnung transparent Wert (alpha oder Transparenz).
globalAlpha Attributwert muss zwischen 0,0 (vollständig transparent) Digital (opak) und 1,0 liegen.
Standard: | 1.0 |
---|---|
JavaScript-Syntax: | Kontext.globalAlpha = Anzahl; |
Eigenschaft Wert
值 | 描述 |
---|---|
number | 透明值。必须介于 0.0(完全透明) 与 1.0(不透明) 之间。 |