admin管理员组

文章数量:1406726

My wordpress plugin works with fabric.js 1.2.0, When I change it to work with fabric.js 1.7.9 then it throws the error on all the pages other than plugin page:

Cannot create property 'style' on string 'wtd_background_image'

on the following line:

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

My wordpress plugin works with fabric.js 1.2.0, When I change it to work with fabric.js 1.7.9 then it throws the error on all the pages other than plugin page:

Cannot create property 'style' on string 'wtd_background_image'

on the following line:

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

Share Improve this question edited Mar 29, 2017 at 15:17 HOY asked Mar 29, 2017 at 15:07 HOYHOY 1,00712 gold badges42 silver badges86 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

You'll need to create an HTML Canvas Element with an id wtd_background_image, on all your pages.

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./ajax/libs/fabric.js/1.7.9/fabric.min.js"></script>

本文标签: