javascript - Fabric.js background appears only after click -
with following code create fabric canvas
canvas = new fabric.canvas('canvas'); canvas.setwidth(660); canvas.setheight(590); fabric.image.fromurl('assets/img/materials/marble.bmp', function(image) { image.set({ // need because image size , canvas size different // in way image covers canvas width:660, height:590 }); canvas.setbackgroundimage(image); }); canvas.renderall();
the canvas created, background image doesn't appear unless click inside canvas, click inside canvas background appears.
i'm working on local machine , application not published online.
why think i'm having problem? doing wrong? how fix behaviour?
fabric.image.fromurl asyncronous. have call renderall() inside callback if want show backgroundimage asap.
otherwise mouse click trigger renderall fraction of second after load finished , background rendered.
canvas = new fabric.canvas('canvas'); canvas.setwidth(660); canvas.setheight(590); fabric.image.fromurl('assets/img/materials/marble.bmp', function(image) { image.set({ // need because image size , canvas size different // in way image covers canvas width:660, height:590 }); canvas.setbackgroundimage(image); canvas.renderall(); });
Comments
Post a Comment