开发者

Detect image load by jQuery

开发者 https://www.devze.com 2023-02-17 01:35 出处:网络
<img src=\"http://site.com/image.png\" /> I change src of this image on .click event. There can be loaded more than 20 different images, after changing src.
<img src="http://site.com/image.png" />

I change src of this image on .click event.

There can be loaded more than 20 different images, after changing src.

1) How do I kno开发者_StackOverflow社区w, was image already loaded (should be cached) or it has to be loaded?

2) How to run two different functions, for loaded and not?

Thanks.


You need to attach an event handler for the load event:

Update 2017:

$('img').on('load', function() {
    alert('new image loaded: ' + this.src);
});

Plain JS/DOM:

imgNode.onload = () => {
    alert('new image loaded: ' + this.src);
};
0

精彩评论

暂无评论...
验证码 换一张
取 消