尝试实现 excanvas 但出现错误

发布于 2024-11-10 18:05:54 字数 780 浏览 8 评论 0原文

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

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 does not support该行上的此属性或方法错误。此外,我在 excanvas.js 内的第 160 行收到一个Invalid argument` 错误。

我的完整代码位于此处。工作页面(除了 IE 之外的所有页面)位于此处。我使用的 excanvas 版本位于此处

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

I'm trying to implement excanvas so that my script works in IE as well as standards compliant browsers. I'm including jquery, excanvas then my script. I'm creating the canvas element like so:

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

But when I try ctx = data.canvas[0].getContext('2d'); I'm getting an Object doesn't support this property or method' error on that line. Additionally I'm getting anInvalid argument` error on line 160 inside excanvas.js.

My full code is here. The working (in everything except IE) page is here. The version of excanvas I'm using is here.

update solved the 2nd error. i had to append the element before calling the init function.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

放肆 2024-11-17 18:05:54

来自文档

如果您已经创建了画布
动态元素不会有
getContext 方法添加到
元素。为了让它工作,你需要
调用 initElement
G_vmlCanvasManager 对象。

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

From the 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');
甜味拾荒者 2024-11-17 18:05:54

画布宽度属性必须是数字。

<canvas width="164" height="164"></canvas>

不是

<canvas width="164px" height="164px"></canvas>

canvas width attribute must be number.

<canvas width="164" height="164"></canvas>

not

<canvas width="164px" height="164px"></canvas>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文