开发者

checking if image is fully loaded

I am using

if (document.getElementById('<%= MainImg.ClientID %>').complete) {
  hideLoadDiv();
}

to hide a div开发者_运维技巧 which indicates the image is not loaded yet,

but it hides before the image has finished loading and is shown, while the browser is giving me a message that the page is still transferring data from the server :S

Is there another function I can use to make sure that the image is fully loaded?


You can use the onload event on the image iteself:

<img src="foo.jpg" onload="hideLoadDiv();" />

Update: looks like your question is a dup


javascript

img = new Image();
img.src = "foo.bar";
img.onload = function() {stuff();};


img = new Image();
img.onload = function() {stuff();};
img.src = "foo.bar";

src should go last

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜