javascript - how to create an image loading animation in Fabric.js? -


im loading images fabric.js canvas using image.fromurl so:

fabric.image.fromurl(url, function(img) {     //blah blah blah     canvas.add(img).setactiveobject(img); }); 

it works, images take few seconds load , user has sit there no feedback. want put in loading animation cant find events can use tell me when image finished loading , ready display.

anyone have solution? thanks!

this should do:

function createcanvasimage(callback) {     //placeholder-code set loading-image spinning      //now load image ajax     var sauce = "http://..."     var request = $.ajax({     url: sauce,     crossdomain: true,     type: "head",     cache: true,     });      //if ajax loaded image, browser have in cache,     //so can add     request.done(function () {     fabric.image.fromurl(sauce, function(img) {             //blah blah blah         canvas.add(img).setactiveobject(img);     });      //placeholder-code stop loading-image     callback();     }); }  createcanvasimage(alert.bind(undefined, "image loading done!")); 

Comments