CSS/HTML method for overlay
If you want an overlay to cover another element or viewport it's doable by only using CSS/HTML which will be alot faster and also works on browsers where JavaScript is disabled.
CSS example
By using absolute positiion we can tell the browser to fill an entire container with a the overlay element, as long as the container element is relatively positioned:
#myPage {
position: relative;
}
#myOverlay {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
z-index: 1000;
}
#myOverlay.fixed {
position: fixed;
}
HTML examples
To cover the #myPage element with the overlay (see on jsFiddle):
<div id="myPage">
<p>This will be covered by the overlay</p>
<div id="myOverlay"></div>
</div>
To cover the entire body, i.e. viewport, put the overlay element right before the closing tag of body
and use fixed positioning (see on jsFiddle):
<body>
<div id="myPage"></div>
<div id="myOverlay" class="fixed"></div>
</body>
JavaScript method to get entire document
To get the entire height of the document (even that what is outside of the viewport) you can use James Padolseys solution which is very simple and works across all browsers:
$.getDocHeight = function(){
return Math.max(
$(document).height(),
$(window).height(),
/* For opera: */
document.documentElement.clientHeight
);
};