javascript - 编辑两个 Canvas 元素

标签 javascript html canvas html5-canvas

我有两个 Canvas 元素,第一个是空的,第二个我画了一个大网格。 在第一个中,我需要添加将被拖动到网格中的文本和图像。问题是,当我向空 Canvas 添加文本时,网格消失了!我不知道这是怎么发生的。我在脚本标记中使用简单的代码:

var canvas=document.getElementById("canvas");
var ctx=canvas.getContext("2d");

var canvas2=document.getElementById("canvas2");
var ctx2=canvas2.getContext("2d");
ctx2.font = "30px Arial";
ctx2.fillText("Catalog of equipments",10,50);

我正在调用正文中的两个 Canvas :

<canvas id="canvas2" width=300 height=1000 style="border:2px solid #c3c3c3; left:320px; top:50px"></canvas>
<canvas id="canvas" width=1000 height=1000 style="border:2px solid #c3c3c3; top:50px;"></canvas>

最佳答案

在您的 jsfiddle 中您将 FillText 拼写为大写 F 而不是 fillText。我已经纠正了这个jsfiddle .

var canvas2 = document.getElementById("canvas2");
var ctx2 = canvas2.getContext("2d");
ctx2.font = "30px Arial";
ctx2.fillText ("Catalog of equipments",10,50);

关于javascript - 编辑两个 Canvas 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22221518/

相关文章:

javascript - Jquery 使用日期选择器计算天数

Javascript form.submit() 仅在调试时有效

android - 移动图像上传先处理?

javascript - <canvas> 中的虚线描边

JavaScript 在 Chrome 中卡住/崩溃

javascript - 如何在面积图中组合 2 个系列 - Highchart

javascript - 在光标位置拆分 div 内容

javascript - 将一系列元素移动到对应的不同div

javascript - 如何在 JSON 文件中添加图像?

java - postInvalidate() 不适用于非 ui 线程