如何使用 HTML 中的指令碼製作圖形?


要使用指令碼製作圖形,請使用 <canvas> 標籤。HTML <canvas> 標籤用於使用指令碼繪製圖形、動畫等。

以下是 <canvas> 標籤的屬性 −

屬性

說明
高度
畫素
指定畫布的高度。
寬度
畫素
指定畫布的寬度。

示例

可以嘗試執行以下程式碼來實現 <canvas> 標籤並建立圖形 −

<!DOCTYPE html>
<html>
   <head>
      <title>HTML Canvas Tag</title>
   </head>
   <body>
      <canvas id = "newCanvas">Your browser does not support canvas tag.</canvas>
      <script>
         var c = document.getElementById('newCanvas');
         var ctx = c.getContext('2d');
         ctx.fillStyle = '#00AEEF';
         ctx.fillRect(0,0,180,50);
      </script>
   </body>
</html>

更新時間: 2020 年 6 月 24 日

675 次瀏覽

激發你的職業生涯

完成課程以獲得認證

開始
廣告