globalAlphaプロパティキャンバスHTML
例
まず、赤色の四角形を描画してから、透明性(globalAlpha)は0.5に設定され、その後、青と緑の四角形を描画:
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);
»をお試しください
ブラウザのサポート
Internet Explorer 9の、Firefoxの、オペラ、ChromeとSafariのサポートglobalAlphaプロパティ。
注:のInternet Explorer 8およびそれ以前のバージョンでは、<キャンバス>要素をサポートしていません。
定義と使用法
globalAlphaプロパティセットや現在の描画透明値(アルファまたは透明度)を返します。
globalAlpha属性値は0.0(完全に透明)デジタル(不透明)と1.0の間でなければなりません。
デフォルト: | 1.0 |
---|---|
JavaScriptシンタックス: | コンテキスト.globalAlpha =数; |
プロパティ値
值 | 描述 |
---|---|
number | 透明值。必须介于 0.0(完全透明) 与 1.0(不透明) 之间。 |
HTMLキャンバスリファレンスマニュアル