GRO*_*ER. 5 javascript google-chrome
当我canvas
在我的网站上测试一个与窗口缩放和元素有关的错误时,我注意到在几次调整大小后,该canvas
元素上印有一张悲伤的小脸(我没有创建)。有谁知道这意味着什么以及它为什么会在那里?
虽然很好笑,但也很混乱。
canvas.width
当将和设置canvas.height
为非常高的值时,似乎会出现问题。以下代码片段复制了该问题(如果您使用的是 Chrome)。
const canvases = document.getElementsByTagName("canvas");
canvases[0].getContext("2d").fillRect(
0,
0,
canvases[0].width,
canvases[0].height,
);
canvases[1].getContext("2d").fillRect(
0,
0,
canvases[1].width,
canvases[1].height,
);
Run Code Online (Sandbox Code Playgroud)
canvas {
width: 100px;
height: 100px;
outline: 1px solid #000000;
}
Run Code Online (Sandbox Code Playgroud)
<p>canvas 1: regular<p>
<!--normal values-->
<canvas width="1000" height="1000"></canvas>
<p>canvas 2: very high width and height<p>
<!--very high values-->
<canvas width="100000" height="100000"></canvas>
Run Code Online (Sandbox Code Playgroud)