JSFiddle - React, Tailwind, and code Playground
HTML
<canvas id="myCanvas" width="440" height="300">
您的浏览器不支持canvas!
</canvas>
CSS
canvas{
border:1px solid #CCC;
}
JavaScript
var canvas = document.getElementById("myCanvas");
if (!canvas.getContext) {
return;
}
var ctx = canvas.getContext("2d");
drawText();
drawHollowText();
function drawText() {
ctx.save();
ctx.font = "12px Arial";
ctx.fillStyle = "#F60";
ctx.fillText("Hello Canvas", 10, 100);
ctx.restore();
}
function drawHollowText() {
ctx.save();
ctx.textAlign = "center";
ctx.font = "12px Arial";
ctx.strokeStyle = "#F60";
ctx.strokeText("Hello Canvas", 220, 230);
ctx.restore();
}