An alpha value that is applied to shapes and images before they are composited onto the canvas.
Property of apis/canvas/CanvasRenderingContext2Dapis/canvas/CanvasRenderingContext2D
Syntaxvar result = CanvasRenderingContext2D.globalAlpha;
CanvasRenderingContext2D.globalAlpha = value;
Return Value
Returns an object of type NumberNumber
Default is 1.0.
ExamplesThe following example draws a semi-transparent white circle on a green background
function draw() {
var ctx = document.getElementById('canvas').getContext('2d');
ctx.fillStyle = '#FD0';
ctx.fillRect(0,0,150,150)
ctx.globalAlpha = 0.2;
ctx.beginPath();
ctx.arc(75,75,50,0,Math.PI*2,true);
ctx.fill();
}
Notes
If you set the globalAlpha property to a value outside the range (including infinity or not a number (NaN)), the previous value is preserved.
Related specificationsThis article contains content originally from external sources, including ones licensed under the CC-BY-SA license.
Portions of this content copyright 2012 Mozilla Contributors. This article contains work licensed under the Creative Commons Attribution-Sharealike License v2.5 or later. The original work is available at Mozilla Developer Network: Article
Microsoft Developer Network: Windows Internet Explorer API reference Article
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4