【问题标题】:FabricJs Cannot read property 'className' of nullfabricjs无法读取空缺的null属性'classname'
【发布时间】:2020-01-20 15:34:42
【问题描述】:

我刚刚将 fabricJs 从 1.4.0 升级到 1.4.13,这样我就可以使用 Image 类的 SetSrc(),当我尝试运行我的应用程序时,我收到了这个错误:“无法读取属性'className' 为 null"。这是错误源自的代码行

   const options = {
              id: client.ProfileId,
              class: 'img_wifiClient',
              left: (transX + client_left) * canvasFabric.scale,
              top: (transY + client_top) * canvasFabric.scale,
              selectable: true,
              hasBorders: false,
              hasControls: false,
              padding: 0,
              perPixelTargetFind: true,
              width: 24,
              height: 24,
              originX: 'center',
              originY: 'center'
       }

       let image = new fabric.Image('');//*This is where the error originated from*
       canvasFabric.add(image);

       let src;


       if (client.IconName === 'default.png' || client.IconName === null)
       {

              src = '/Icones/wifi.png';
       }
       else
       {

              src = `/Icones/${client.IconName}`;
       }

        image.setSrc(src, function () {
              image.setCoords();
              canvasFabric.renderAll();
         }, options);

任何帮助将不胜感激!

【问题讨论】:

    标签: fabricjs


    【解决方案1】:

    我在 Html 文件的 canvas 元素下添加了一个 id = "myIcone" 的 img 元素,并添加了以下代码行,一切正常。

     let image_element = document.getElementById('myIcone');
     let image = new fabric.Image(image_element);
     canvasFabric.add(image); 
    

    其余代码同问题sn-p

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-29
      • 1970-01-01
      • 2020-11-08
      相关资源
      最近更新 更多