使用Image.fromURL将图像加载到我的Fabric.js画布中,如下所示:
fabric.Image.fromURL(url, function(img) {
//blah blah blah
canvas.add(img).setActiveObject(img);
});
它可以工作,但有些图像需要几秒钟才能加载,用户必须坐在那里没有任何反馈。我想放一个加载动画,但我找不到任何可以用来告诉我图像加载完毕并准备好显示的事件。
任何人都有解决方案吗?谢谢!
答案 0 :(得分:0)
这应该做:
function createCanvasImage(callback) {
//Placeholder-Code to set the loading-image spinning
//Now load the image with AJAX
var sauce = "http://..."
var request = $.ajax({
url: sauce,
crossDomain: true,
type: "HEAD",
cache: true,
});
//If AJAX loaded your image, the browser will have it in cache,
//so now we can add it
request.done(function () {
fabric.Image.fromURL(sauce, function(img) {
//blah blah blah
canvas.add(img).setActiveObject(img);
});
//Placeholder-Code to stop the loading-image
callback();
});
}
createCanvasImage(alert.bind(undefined, "Image loading done!"));