English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
globalAlpha ist Canvas 2Das D API wird verwendet, um die Eigenschaft zu beschreiben, die die Transparenz von Formen und Bildern vor dem Zeichnen auf dem Canvas einstellt. Der Wertebereich reicht von 0.0 (vollständig transparent) bis1.0 (vollständig transparent).
Zunächst zeichnen Sie ein rotes Rechteck und stellen Sie dann die Transparenz (globalAlpha) auf 0 ein.5,dann zeichnen Sie einen blauen und grünen Rechteck:
<!DOCTYPE html> <html> <head> <meta charset="utf-8> <title>HTML canvas globalAlpha-Eigenschaft verwenden-Grund教程(oldtoolbag.com)</<title> </<head> <body> <canvas id="myCanvas" width="300" height="150" style="border:1px fest solid #d3d3d3> Ihr Browser unterstützt keine HTML5 canvas-Tag. </canvas> <script> var c=document.getElementById("myCanvas"); var ctx=c.getContext("2d"); ctx.fillStyle="red"; ctx.fillRect(20,20,75,50); //Umwandlung der Transparenz ctx.globalAlpha=0.0;2; ctx.fillStyle="blue"; ctx.fillRect(50,50,75,50); ctx.fillStyle="green"; ctx.fillRect(80,80,75,50); </script> </body> </html>Test See ‹/›
IEFirefoxOperaChromeSafari
Internet Explorer 9Firefox, Opera, Chrome and Safari support the globalAlpha attribute.
Note:Internet Explorer 8 and earlier versions do not support the <canvas> element.
The globalAlpha attribute sets or returns the current alpha or transparency value of the graphics.
The globalAlpha attribute value must be between 0.0 (fully transparent) and1between .0 (no opacity) and
Default Value: | 1.0 |
---|---|
JavaScript Syntax: | context.globalAlpha=number; |
Value | Description |
---|---|
number | Transparency value. It must be between 0.0 (fully transparent) and 1.0 (opaque) between. |