i am wanting to implement a solution where:
- whilst contents in div #content are loading,
- hide div #content,
- show div #loading,
- then when div #content has loaded,
- hide div #loading,
- fade in div #content
i have tried:
html:
<div id="content">
<!--this stuff takes a long time to load-->
<img src="http://lorempixel.com/1920/1920/">
</div>
<div id="loading">
<!-- this is the loading gif -->
<img src="http://lorempixel.com/400/200/">
</div>
js:
// when user browses to page
$('#content').hide();
$('#loading').show();
// then when div #content has loaded, hide div #loading and fade in div #content
$('#content').bind('load', function() {
$('#loading').hide();
$('#content').fadeIn('slow');
});
here is the jsfiddle i am working on:
http://jsfiddle.net/rwone/Y9CQ4/
thank you.
According to .load(), the event should fire, when
So, you cannot bind the load event handler to a
divtag. When you want the event handler to fire after the image has loaded, you must bind it to the imageHTML:
JS:
JSFiddle
Or you can bind the event to the
windowobject, which fires whenJS:
JSFiddle
Yet a third approach, would be to test if all images are loaded, when the load event fires
JSFiddle