How to verify background (css) image was loaded?

前端 未结 5 1387
离开以前
离开以前 2021-02-03 22:00

I have the following CSS class that I\'m applying on a tag:

.bg {
   background-image: url(\'bg.jp         


        
5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-03 22:41

    You also can provide a function that simply replaces the img tag by the div/background so that you benefit from both the onload attribute and the flexibility of the div.

    Of course, you can fine tune the code to best suits your need, but in my case, I also make sure that either the width or the height is preserved for a better control of what I expect.

    My code as follows:

    
    
    
    
    
    

提交回复
热议问题