【问题标题】:Uncaught InvalidStateError: An attempt was made to use an object that is not, or is no longer, usablee未捕获的 InvalidStateError:尝试使用不可用或不再可用的对象
【发布时间】:2014-05-21 06:54:47
【问题描述】:
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;
            }

我正在使用动力学 js,字符串是正确的,图像文件存在,但是在我分配 src 后发生错误,无法弄清楚,我也试过这个:

var url = escape('<?= URL::to(''); ?>/img/' + node.main_photo);

但它没有帮助,有什么想法吗??

这个错误是什么意思?我能做些什么来解决它?

【问题讨论】:

  • 你能创建任何 jsfiddle 演示吗?

标签: javascript php image canvas kineticjs


【解决方案1】:

您必须等到图像加载完毕,然后才能创建Kinetic.Image 对象。

var img = new Image();
img.onload = function() {
    var image = new Kinetic.Image({
       image : img
    });
}
img.src = 'url';

演示:http://jsbin.com/gibeq/1/edit

【讨论】:

    猜你喜欢
    • 2014-05-19
    • 2013-10-08
    • 2016-04-30
    • 2019-03-05
    • 2013-09-24
    • 2013-12-08
    • 2022-08-18
    • 1970-01-01
    • 2013-06-17
    相关资源
    最近更新 更多