【问题标题】:Image readystate in canvas画布中的图像就绪状态
【发布时间】:2011-02-20 23:12:29
【问题描述】:

是否可以在画布中使用 imagename.readyState?

如果没有,是否有人知道一种方法来检测使用“drawImage”绘制到画布上的图像何时已加载并准备好显示?

I am creating an image showcase using the canvas - when an image is selected I want to have a loading animation (which I have already created) display until the loaded condition is met.

我仍在学习使用 javascript,并且整天都在尝试无济于事 - 因此,对于缺少示例代码来显示和说明我的要求,我们深表歉意!

【问题讨论】:

    标签: javascript canvas loading drawimage loaded


    【解决方案1】:

    您可以尝试使用new Image() 加载图像并设置.onload 事件以在图像加载后在画布上绘制图像。

    var img = new Image();
    img.onload = function() {
        // code to draw image on the canvas...
    }
    img.src = "/path/to/img.jpg";
    

    另请参阅:https://developer.mozilla.org/samples/canvas-tutorial/3_1_canvas_drawimage.html

    【讨论】:

    • 还有其他检测方法吗?我尝试使用它,但对于我想要做的事情我并不高兴 - 我需要能够检测图像何时加载(或卸载)。
    猜你喜欢
    • 1970-01-01
    • 2021-07-10
    • 1970-01-01
    • 2012-12-14
    • 1970-01-01
    • 2015-08-21
    • 1970-01-01
    • 2011-03-16
    • 1970-01-01
    相关资源
    最近更新 更多