如果我设置
ctx.textBaseline = "top";
,但然后调整画布大小,ctx.textBaseline
会被改回"alphabetic"
。这是期望的行为吗?这个问题让我困扰了一段时间,所以我只是好奇。在Chrome和Firefox中发生,所以我的初步猜测是这是期望的行为。
// textBaseline not working:
let ctx1 = canvas1.getContext("2d");
ctx1.textBaseline = "top";
canvas1.width = 31;
canvas1.height = 31;
ctx1.fillText("hi", 10, 10);
// fixed:
let ctx2 = canvas2.getContext("2d");
canvas2.width = 31;
canvas2.height = 31;
ctx2.textBaseline = "top"; // <-- need to set it *after* resize to get it to work
ctx2.fillText("hi", 10, 10);
谢谢!