In accordance with . load () event should fire when
A load event is dispatched to an element when it and all sub-elements have been fully loaded. This event can be dispatched to any element associated with the URL : images, scripts, frames, iframes, and window objects.
, div. , ,
HTML:
<div id="content">
<img id="large" src="http://lorempixel.com/1920/1920/">
</div>
<div id="loading">
<img src="http://lorempixel.com/400/200/">
</div>
JS:
$('#content').hide();
$('#loading').show();
$('#large').bind('load', function() {
$('#loading').hide();
$('#content').fadeIn('slow');
});
JSFiddle
window, ,
, .
JS:
$(window).bind('load', function() {
$('#loading').hide();
$('#content').fadeIn('slow');
});
JSFiddle
, - , ,
function allImagesLoaded() {
var imgs = $(this).closest('div').find('img');
var loaded = 0;
imgs.each(function() { if ($(this.complete)) ++loaded; });
if (imgs.length == loaded) {
$('#loading').hide();
$('#content').fadeIn('slow');
}
}
$('#content').hide();
$('#loading').show();
$('#content img').bind('load', allImagesLoaded);
JSFiddle