跳至內容

HTML/Canvas

維基教科書,自由的教學讀本

<canvas> tag允許腳本化地繪製2D形狀。

繪製一個Canvas:

<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);