gpt4 book ai didi

javascript - 尝试实现 excanvas 但出现错误

转载 作者:行者123 更新时间:2023-11-29 10:23:45 25 4
gpt4 key购买 nike

我正在尝试实现 excanvas,以便我的脚本可以在 IE 和符合标准的浏览器中运行。我包括 jquery、excanvas 然后是我的脚本。我正在像这样创建 Canvas 元素:

data.canvas = $(document.createElement('canvas')).attr('width', data.fontwidth * 80 + 'px').attr('height', data.fontheight * 25 + 'px');
$this.append(data.canvas);

但是当我尝试 ctx = data.canvas[0].getContext('2d'); 时,我得到一个 Object doesn't support this property or method' 错误那条线。此外,我在 excanvas.js 的第 160 行收到了一个Invalid argument` 错误。

我的完整代码是 here .工作页面(除 IE 之外的所有内容)是 here .我使用的 excanvas 版本是 here .

更新 解决了第二个错误。我必须在调用 init 函数之前附加元素。

最佳答案

来自docs :

If you have created your canvas element dynamically it will not have the getContext method added to the element. To get it working you need to call initElement on the G_vmlCanvasManager object.

var el = document.createElement('canvas');
G_vmlCanvasManager.initElement(el);
var ctx = el.getContext('2d');

关于javascript - 尝试实现 excanvas 但出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6193513/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com