如果我设置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);
谢谢!