$( 'img' ).load( function(){ ... });
– 不是你可以信任的东西(在你的插件中我看到了这段代码)。在这里您可以看到原因:
http ://api.jquery.com/load-event/ (从caveats
单词开始阅读)
这是描述问题的小例子:
$( document ).ready( function(){
$( 'img' ).load( function(){
// this event going to fire only if document was ready after image was loaded; (very seldom, almost never)
console.log( 'Fired?! You are lucky today!' );
});
$( document.body ).append( '<img src="http://stat19.privet.ru/lr/0b164d8151948d2fdedfbfdc420f5392?temp=2" id="some"/>' );
$( '#some' ).load( function(){
// this event will fire often, except of cases descripted in `load` event manual
console.log( 'Huugh. Today have fired. But I don\'t know about tomorrow' );
});
var temp = new Image;
temp.src = 'http://photo.a42.ru/photos/92772/medium/11757.jpg';
temp.onload = function(){
// this event going to fire almost always except of cache issue with IE, that can be handled by skipping cache with `?nothing=random` appending to image URL
console.log( 'Okay, okay! I\'ve fired' );
}
$( document.body ).append( temp );
});
你可以在这里运行它:http: //jsfiddle.net/p6Cpy/