Miroo
Miroo

Reputation: 805

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?

Upvotes: 1

Views: 2414

Answers (3)

Lev Savranskiy
Lev Savranskiy

Reputation: 430

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

src should go last

Upvotes: 0

javascript

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

Upvotes: 1

The Scrum Meister
The Scrum Meister

Reputation: 30111

You can use the onload event on the image iteself:

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

Update: looks like your question is a dup

Upvotes: 1

Related Questions