*Note: This is not concerning img tags. This is strictly a question about CSS background images.
I am trying to make a nice ajax-based template that does not refresh the page, but rather exchanges the content within a specific div. Everything is working well, except that the background images are never fully loaded by the time the newly loaded div is revealed to the user. I would expect the process to look like this:
- HTML content is loaded.
- The CSS images begin to load asynchronously.
- The callback function runs to completion.
For the sake of testing, I delayed the reveal just to make sure the images would have time to load before the function finished. Even with 5 extra seconds, it still displays blank boxes where images should be for a second before loading, no matter how long it's delayed. This leads me to conclude the flow must be acting more like this:
- HTML content is loaded.
- The callback function runs to completion.
- The CSS images begin to load asynchronously.
The "load" event does not seem to account for CSS images, and there does not seem to be any event that allows a script to wait for the CSS images to finish loading.
I even tried hacking around it by looping through every single element, checking for the presence of a background image, then creating a new Image() with a load event for each one, but that, needless to say, exceeds the call stack.
So my question is, how can I simply wait for all background images to fully display before moving forward with the script?