用firefox的canvas標籤繪製簡單的圖形(firefox下可以執行,IE不可以)

用firefox繪製的三個矩形,第一個爲不透明紅色,第二個爲透明度爲0.5的藍色,第三個爲透明度爲0.5的綠色

firefox的canvas標籤確實很是不錯啊,感覺很神奇!

代碼 如下,必須在firefox下才能執行以下代碼

<html>
 <head>
  <script type="application/x-javascript">
function draw() {
 var canvas = document.getElementById("canvas");
 var ctx = canvas.getContext("2d");

 ctx.fillStyle = "rgb(200,0,0)";  // 把「填滿樣式」設為紅 200 綠 0 藍 0
 ctx.fillRect (10, 10, 30, 30);   // 畫一個填充的長方形

 ctx.fillStyle = "rgba(0, 0, 200, 0.5)"; // 把「填滿樣式」設為紅 0 綠 0 藍 200 透度 0.5
 ctx.fillRect (20, 20, 30, 30);          // 畫一個填充的長方形


 ctx.fillStyle = "rgba(0, 200, 0, 0.5)"; // 把「填滿樣式」設為紅 0 綠 200 藍 0 透度 0.5
 ctx.fillRect (30, 30, 30, 30);          // 畫一個填充的長方形
}
  </script>
 </head>
 <body οnlοad="draw()">
   <canvas id="canvas" width="300" height="300"></canvas>
 </body>
</html>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章