开发者

Image loading: JavaScript onLoad and Image::complete (FireFox 3)

When loading images into a JavaScript Image object, I would presume that, once the load event is triggered for an image i, then i.complete should be true. Either that is not happening or (more likely, I suspect) I have a bug in my jQuery/JavaScript code.

The code (stripped way down, but I'开发者_如何学Gom quite confident that what is relevant is here)

$img = $('<img />');  // This line added by edit for clarification
var eventData = {
        sheet: this,
        resolution: resolution,
        i: i,
    };

$img.bind('load', eventData, onTileLoad);
$img.attr('src', tile.src);

onTileLoad = function(ev) {
    var sheet = ev.data.sheet;
    var resolution = ev.data.resolution;
    var i = ev.data.i;

    if (!this.complete) {
        console.log('Image load not complete: sheet ' + sheet.sheetName + 
                ', resolution ' + resolution + ' tile ' + i)
    };

    ....
};

This console log triggers for some, but by no means most, of my images. I would think it should never trigger. For what it's worth, I'm working in FireFox 3.6.18 (because it is very stable and has good developer tools).

Anyone know what might be going on?


What $img refers to ?

In the onTileLoad function, this refers to $img. If $img is a jQuery object (as it looks like), it has no complete property. The complete property is set on the DOM object only.

Look at this test case.

Hope this will help,

Cheers

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜