2 html javascript text canvas outline
在画布上绘图时,如何在JavaScript中为文本提供大纲?请参阅下面我尝试做的图片.

小智 7
Daniel Langh向我展示了解决方案:
var txt = 'Hello World!';
var x = 30,
y = 50;
context.font = "40px Helvetica";
context.strokeStyle = 'white';
// setup these to match your needs
context.miterLimit = 2;
context.lineJoin = 'circle';
// draw an outline, then filled
context.lineWidth = 7;
context.strokeText(txt, x, y);
context.lineWidth = 1;
context.fillText(txt, x, y);
Run Code Online (Sandbox Code Playgroud)