Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
162
rated 0 times [  163] [ 1]  / answers: 1 / hits: 34036  / 15 Years ago, fri, december 18, 2009, 12:00:00

I have the following CSS class that I'm applying on a <td> tag:


.bg {
background-image: url('bg.jpg');
display: none;
}

How can I tell with JavaScript/jQuery that the background image finished loading?


More From » jquery

 Answers
11

The only way I know of to do this is to load the image using Javascript, and then set that image as the backgroud.



For example:



var bgImg = new Image();
bgImg.onload = function(){
myDiv.style.backgroundImage = 'url(' + bgImg.src + ')';
};
bgImg.src = imageLocation;

[#98041] Tuesday, December 15, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
margob

Total Points: 302
Total Questions: 89
Total Answers: 100

Location: Guadeloupe
Member since Sat, Jul 25, 2020
4 Years ago
margob questions
Mon, Jun 29, 20, 00:00, 4 Years ago
Wed, Sep 26, 18, 00:00, 6 Years ago
;