【问题标题】:Uncaught TypeError: Cannot read property 'width' of null未捕获的类型错误:无法读取 null 的属性“宽度”
【发布时间】:2013-05-02 19:48:47
【问题描述】:

我正在尝试使用 fabric.js,现在我正在尝试放入一个图像进行试验。

我关注了the tutorial,但即便如此我还是收到以下错误:

Uncaught TypeError: Cannot read property 'width' of null

... 指 all.js 中的第 14805 行:

_setWidthHeight: function(options) {
    this.width = 'width' in options
        ? options.width
        : (this.getElement().width || 0);    // <------ this line
    this.height = 'height' in options
        ? options.height
        : (this.getElement().height || 0);
},

我的代码(html):

...
<div id="avatarBox">
    <canvas id="canvas" width="500" height="500"/>
    <img src="img/test.png" id="my-image">
</div>
...

我的代码(js):

var canvas = new fabric.Canvas('canvas');
var imgElement = document.getElementById('my-img');

var imgInstance = new fabric.Image(imgElement, {
    left: 100,
    top: 100,
    angle: 30,
    opacity: 0.85
});

canvas.add(imgInstance);

有什么问题?

【问题讨论】:

    标签: javascript jquery instance fabricjs


    【解决方案1】:

    您的 html 中没有“my-img”。你有“我的形象”,也许问题来自那里?

    【讨论】:

    • 太好了,没看到那个!然后他们的文档出错了...谢谢!
    猜你喜欢
    • 2014-11-18
    • 2021-11-18
    • 2019-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-19
    • 2021-12-01
    相关资源
    最近更新 更多