gpt4 book ai didi

javascript - 未捕获的类型错误 : Cannot create property 'style' on string 'wtd_background_image'

转载 作者:搜寻专家 更新时间:2023-10-31 22:55:35 24 4
gpt4 key购买 nike

我的 wordpress 插件适用于 fabric.js 1.2.0,当我将其更改为适用于 fabric.js 1.7.9 时,它会在除插件页面以外的所有页面上抛出错误:

Cannot create property 'style' on string 'wtd_background_image'

在下面一行:

canvasObj= new fabric.Canvas('wtd_background_image');

enter image description here

最佳答案

您需要在所有页面上创建一个 id 为 wtd_background_image 的 HTML Canvas 元素。

let canvas = new Canvas('wtd_background_image');
let canvasObj = new fabric.Canvas('wtd_background_image');

function Canvas(id) {
this.canvas = document.createElement('canvas');
this.canvas.id = id;
document.body.appendChild(this.canvas);
return this.canvas;
}

// for demonstration
let circle = new fabric.Circle({radius: 20, fill: '#07C', left: 30, top: 30});
canvasObj.add(circle);
<script src="http://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.7.9/fabric.min.js"></script>

关于javascript - 未捕获的类型错误 : Cannot create property 'style' on string 'wtd_background_image' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43097398/

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