Uncaught InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable.
在这行代码中发生:
var nodeIconImg = new Image();
var nodeIcon = new Kinetic.Image({
image: nodeIconImg,
width: 30,
height: 30,
cornerRadius: radius
});
if(node.main_photo == 'no_photo.png')
{
var url = '<?= URL::to(''); ?>/img/' + node.main_photo;
nodeIconImg.src = url;
}
我正在使用kinetic js,字符串是正确的,图像文件存在,但在我分配src后发生错误,无法弄明白,我也试过了:
var url = escape('<?= URL::to(''); ?>/img/' + node.main_photo);
但它没有帮助,任何想法??
这个错误意味着什么?我该怎么做才能解决它?
答案 0 :(得分:0)
在创建Kinetic.Image
对象之前,您必须等到加载图像。
var img = new Image();
img.onload = function() {
var image = new Kinetic.Image({
image : img
});
}
img.src = 'url';