跳至內容

超文字標記語言/Canvas

來自 Wikibooks,開放世界中的開放書籍

<canvas> 標籤允許用指令碼方式繪製 2D 圖形。雖然畫布嵌入在 HTML 頁面中,但可以利用 JavaScript 繪製畫布。

渲染畫布

<canvas id="e">This text will be displayed if the browser does not support canvas.</canvas>

JavaScript

var Canvas=document.getElementById("e");
var Context=Canvas.getContext("2d");
context.fillStyle="green";
context.fillRect(30,40,30,20);
context.strokeStyle="red";
context.strokeRect(30,40,30,20);
context.strokeText("Hello",30,40);
context.fillText("World",30,50);
華夏公益教科書