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

前端 未结 7 1687
温柔的废话
温柔的废话 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:33

    Yes, I was just working on an AJAX page that dynamically loaded images. I also wanted to detect if images were loaded so I could transition them in with a jQuery effect.

    img = $('myImageID')
    img[0].src = 'http://new.url.for.image/';
    alert(img[0].complete);                    // seems to always return true
                                               // in Firefox, perhaps because
                                               // the original src had been loaded
    

    So instead I had to do this...

    img = $('myImageID')
    newImg = $('')                // create a completely new IMG element
              .attr('src', 'http://new.url.for.image/')
              .attr('id', img[0].id);
    img.replaceWith(newImg);
    img = newImg;
    alert(img[0].complete);
    

    (Note: I haven't tested this exact code, it's a simplified version of what I was trying to do, but hopefully communicates the idea.)

    Simon.

提交回复
热议问题