Random javascript css image uploaded

Is there any way to detect that a css background image is loaded? Using regular tags would be easy, but I need to use a css background because I place divs above the image. The reason I need to find that this image has been uploaded is because I do not want to preload additional images before the background image is shown.

+4
source share
2 answers

You can force the background image to be downloaded to the client browser using traditional javascript methods to preload the images. After downloading it, it will be cached by the client and will be displayed instantly when you edit css background-image in javascript.

Be careful, this is bad practice for progressive improvement. In other words, the look of your webpage will be limited to browser support for javascript.

+1
source

There was the same problem. After thinking about this for a while, I made an <img> below a <div> that had a background, and positioned it as a background using css. Then attach onLoad to it :)

0
source

All Articles