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?
Make sure the image path is set correctly in the background-image url. Once you have made sure that your CSS file is linked correctly, also check that the image itself is set correctly. Again, you will want to open your code inspector in the browser to check.
To download a background image, Ctrl -click or right-click the image and, from the menu that appears, select View Source or View Frame Source. Find the URL for the background image in the document's <body> tag (it should be near the top).
Assuming that your . png file actually exists, try setting the background size and repeat tags. If that doesn't work, try checking in your browser's developer tools for the response codes and making sure that the url is correct.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With