Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
14
rated 0 times [  19] [ 5]  / answers: 1 / hits: 138303  / 14 Years ago, wed, august 18, 2010, 12:00:00

I'm creating new image using



img = new Image();
img.src = image_url;


Then I'm assigning img.src to the img tag's src in DOM



$(#my_img).attr(src, img.src);


How can I know that img.src has 100% loaded? What is the best practice?
img.complete seem to me little buggy in some browsers.



So, in another words, I need to assign img.src to $(#my_img) only after img it was 100% loaded.



Thank you!


More From » jquery

 Answers
14

Use the load event:



img = new Image();

img.onload = function(){
// image has been loaded
};

img.src = image_url;


Also have a look at:




[#95879] Monday, August 16, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
pierce

Total Points: 315
Total Questions: 103
Total Answers: 89

Location: Svalbard and Jan Mayen
Member since Mon, Jun 7, 2021
3 Years ago
;