I am having an issue where my DOM is not displaying when my window.onload (or ) fires. In my actual project, the javascript function I call is gathering quite a bit of data, so I am trying to simply display a splash style screen first. Easy...but it is not working as I expect and I feel I am missing something. I have seen similar questions, but most of them have an 'alert' as part of the testing solution. Anything that breaks the script running allows the DOM to display...so these 'solutions' are not fixing my issue. If I step through the code (IE or Chrome), then all works fine. Here is a sample that reproduces the issue. At least when I run this in Chrome, nothing displays until the 3rd second...then the alert pops and the Loading div shows. In IE, Loading Div does not show until all 5 seconds pass and function completes. Thanks in advance for any thoughts!
<!DOCTYPE html>
<html lang="en">
<head>
<style>
#Loading{
position: absolute;
Left: 50px;
Top: 50px;
width: 100%;
height: 100%;
background-color: yellow;
display: block;
}
</style>
<script>
window.onload = Hmm;
function Hmm(){
i = 0;
while (i < 5){
sleep(1000);
i++;
if (i == 3) {
alert("hi");
}
}
}
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
</script>
</head>
<body>
<div id="Loading">Loading...</div>
</body>
</html>