HTML canvas globalAlpha Property |
-- Learning is not just about technology, but also about dreams!
- Home
- HTML
- JavaScript
- CSS
- Vue
- React
- Python3
- Java
- C
- C++
- C#
- AI
- Go
- SQL
- Linux
- VS Code
- Bootstrap
- Git
- Local Bookmarks
JavaScript Reference
JavaScript Objects
- JavaScript Array Object
- JavaScript Boolean Object
- JavaScript Date Object
- JavaScript Math Object
- JavaScript Number Object
- JavaScript String Object
- JavaScript RegExp Object
- JavaScript Global Properties/Functions
- JavaScript Operators
- JavaScript Error
Browser Objects
DOM Objects
- HTML DOM Document Object
- HTML DOM Element Object
- HTML DOM Attribute Object
- HTML DOM Event Object
- HTML DOM Console Object
- CSSStyleDeclaration Object
- DOM HTMLCollection
HTML Objects
- <a>
- <area>
- <audio>
- <base>
- <blockquote>
- <body>
- <button>
- <canvas>
- <col>
- <colgroup>
- <datalist>
- <del>
- <details>
- <dialog>
- <embed>
- <fieldset>
- <form>
- <iframe>
- <frameset >
- <img>
- <ins>
- <input> - button
- <input> - checkbox
- <input> - color
- <input> - date
- <input> - datetime
- <input> - datetime-local
- <input> - email
- <input> - file
- <input> - hidden
- <input> - image
- <input> - month
- <input> - number
- <input> - range
- <input> - password
- <input> - radio
- <input> - reset
- <input> - search
- <input> - submit
- <input> - text
- <input> - time
- <input> - url
- <input> - week
- <keygen>
- <link>
- <label>
- <legend>
- <li>
- <map>
- <menu>
- <menuItem>
- <meta>
- <meter>
- <object>
- <ol>
- <optgroup>
- <option>
- <param>
- <progress>
- <q>
- <script>
- <select>
- <source>
- <style>
- <table>
- <td>
- <th>
- <tr>
- <textarea>
- <title>
- <time>
- <track>
- <video>
Explore Further
- Programming Languages
- Programming
- Software
- Web Services
- Web Design and Development
- Scripting
- Web Service
- Scripting Language
- Computer Science
- Development Tools
HTML canvas globalAlpha Property
Example
First, draw a red rectangle, then set the transparency (globalAlpha) to 0.5, and then draw a blue and a green rectangle:
Your browser does not support the HTML5 canvas tag.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);
Browser Support
The globalAlpha property is supported in Internet Explorer 9, Firefox, Opera, Chrome, and Safari.
Note: Internet Explorer 8 and earlier versions do not support the <canvas> element.
Definition and Usage
The globalAlpha property sets or returns the current transparency value (alpha or transparency) for drawing.
The globalAlpha property value must be a number between 0.0 (fully transparent) and 1.0 (fully opaque).
| Default value: | 1.0 |
|---|---|
| JavaScript syntax: | context.globalAlpha=number; |
Property Values
| Value | Description |
|---|---|
| number | The transparency value. Must be between 0.0 (fully transparent) and 1.0 (fully opaque). |
ByteDance Coding Plan supports Doubao, GLM, DeepSeek, Kimi, MiniMax and other mainstream large models, officially supplied, stable and reliable. Configuration Guide Β₯9.9/month Subscribe Now
YouTip