Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>HTML5 Canvas Transparency</title>
- </head>
- <body>
- <canvas id="MyCanvas" width="650" height="600"></canvas>
- <script>
- var canvas = document.getElementById("MyCanvas");
- if (canvas.getContext) // Test for support.
- {
- var ctx = canvas.getContext("2d"); // Get the context to draw on.
- for (var g = 0,x=0, y=25; g <= 10; g+=1, x+=25, y+=25)
- {
- ctx.globalAlpha = g/10;
- ctx.fillStyle = "red";
- ctx.strokeStyle = "black";
- ctx.fillRect(x, y, 200, 200); // Create a filled rectangle.
- ctx.strokeRect(x, y, 200, 200); // Put an outline around it
- ctx.globalAlpha = 1;
- ctx.fillStyle = 'blue';
- ctx.font = "14px Unknown Font, sans-serif";
- ctx.fillText(" Transparency Value "+g, 202+x, y+10);
- ctx.globalAlpha = g/10;
- }
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement