On a button click I want to make a div
that is the entire width and height of the page. Not just the visible page but the entire rendered document.
So far I am using Javascript from this SO anser to calculate the height:
var B = document.body,
H = document.documentElement,
height;
if (typeof document.height !== 'undefined') {
height = document.height;
} else {
height = Math.max( B.scrollHeight, B.offsetHeight, H.clientHeight, H.scrollHeight, H.offsetHeight );
}
var overlay = document.createElement('div');
overlay.style.position = 'absolute';
overlay.style.width = window.innerWidth + 'px';
overlay.style.height = height + 'px';
overlay.style.top = window.scrollY + 'px';
overlay.style.left = 0;
However this does not always work. Sometimes when I am scrolled down to the bottom of the page the overlay starts lower on the page and extends the length of the document significantly. Sometimes it works right and sometimes it does not. I know there are ways to do this with jQuery but I do not want to use this.
Bonus points would be the best way to keep the overlay stretching across the entire screen width upon windows resize....Thanks