Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>HTML5 canvas transparent rectangles</title>
- <script>
- function draw() {
- var canvas = document.getElementById('myCanvas');
- var ctx = canvas.getContext('2d');
- ctx.fillStyle ="green";
- ctx.globalAlpha=0.1;
- ctx.fillRect(0, 0, 1024, 768);
- for (var i = 1; i <= 10; i++) {
- ctx.fillStyle ="black";
- var alpha = i * 0.1;
- ctx.globalAlpha = alpha;
- ctx.fillRect(50*i, 20, 40, 40);
- }
- }
- </script>
- <style>
- body{
- background-color: brown;
- }
- </style>
- </head>
- <body onload="draw();" >
- <canvas id="myCanvas" width="550" height="200">
- </canvas>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement