【问题标题】:How to know when an image load completes [duplicate]如何知道图像加载何时完成[重复]
【发布时间】:2012-05-21 09:22:14
【问题描述】:

可能重复:
JavaScript: Know when an image is fully loaded

我有这个代码:

$("#imageOnPage").attr("src", urlString);

图像在屏幕上可见后,我需要以某种方式触发事件。 换句话说,我需要图像的 onLoad 事件。

【问题讨论】:

标签: jquery


【解决方案1】:

实际上有一个事件:

$('#imageOnPage').load(function()
{
/* your code */
});

当你的图片加载完毕时它会被触发。

【讨论】:

    【解决方案2】:

    您应该能够绑定到图像的load 事件。

    $('#imageOnPage').load(function() {
        alert('image loaded');
    });
    

    【讨论】:

      【解决方案3】:
      $('#imageOnPage').load(function(){
        $(this).attr('src', urlString);
      });
      

      【讨论】:

        猜你喜欢
        • 2022-05-13
        • 1970-01-01
        • 2010-11-18
        • 2011-07-05
        • 1970-01-01
        • 2010-12-12
        • 2014-12-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多