What workarounds exist for the `complete` property in FireFox?

前端 未结 7 1689
温柔的废话
温柔的废话 2020-12-17 16:31

I am attempting to use jQuery to determine if an image has properly loaded.

The following works just fine (and returns true or false as of

相关标签:
7条回答
  • 2020-12-17 17:34

    You could also try checking the one of the dimensions of the img element in addition to complete:

    function isImageLoaded() {
        var theImage = $('#myImage'); 
    
        if (!theImage.get(0).complete) {
            return false;
        }
        else if (theImage.height() === 0) {
            return false;
        }
    
        return true;
    }
    

    An unloaded img or an img with an invalid src attribute should have .height() and .width() equal to 0 in Firefox. In Chrome and Opera neither method appears to work properly. In those browsers theImage.height() always returned a positive value in my testing.

    0 讨论(0)
提交回复
热议问题