1304353-text-global-alpha-2-ref.html 879 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <script>
  6. function do_test() {
  7. var canvas = document.getElementById("test");
  8. var ctx = canvas.getContext("2d");
  9. var g = ctx.createLinearGradient(0, 0, canvas.width, canvas.height);
  10. g.addColorStop(0, "red");
  11. g.addColorStop(1, "green");
  12. ctx.fillStyle = g;
  13. ctx.fillRect(0, 0, canvas.width, canvas.height);
  14. ctx.strokeStyle = "white";
  15. ctx.font = "bold 24px sans-serif";
  16. ctx.strokeText('globalAlpha = 1.0', 20, 40);
  17. // for reference, use a stroke color with alpha instead of global alpha
  18. ctx.strokeStyle = "rgba(255, 255, 255, 0.5)";
  19. ctx.strokeText('globalAlpha = 0.5', 20, 80);
  20. ctx.strokeStyle = "rgba(255, 255, 255, 0.2)";
  21. ctx.strokeText('globalAlpha = 0.2', 20, 120);
  22. };
  23. </script>
  24. </head>
  25. <body onload="do_test()">
  26. <canvas id="test"></canvas>
  27. </body>
  28. </html>