I have a large page where the DOM takes a while to completely load. I thought it would be good to have a little loading animation appear whilst the page is loading so I implemented this:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="https://github.com/Modernizr/Modernizr/raw/master/modernizr.js"></script>
<script>
// Wait for window load
$(window).load(function() {
// Animate loader off screen
$("#wait").animate({
top: -200
}, 1500);
});
</script>
<body>
<div id="wait">
<img src="/assets/images/ajax-loader.gif" />
</div>
(found here)
It works but only at the very last moment, when the DOM is about 4/5ths already loaded. Was hoping if anyone knew a better way to do this?