According to documentation for Javascript's window.innerWidth and window.innerHeight properties, both are calculated without toolbars and scroll bars. However, when I try to set a div element and a canvas element to be the same size as the window, both elements have excess on their width and the height properties. How do I go about fixing this?
HTML
<body>
<div id="gameScreen">
<canvas id="basemap"></canvas>
</div>
</body>
CSS
html, body{
margin: 0;
padding: 0;
}
#gameScreen{
margin: 0;
padding: 0;
border: 1px solid black;
}
#basemap{
margin: 0;
padding: 0;
background-color: red;
}
JS
function sizePage(){
var gameScreen = document.getElementById("gameScreen");
var basemap = document.getElementById("basemap");
var canvasWidth = window.innerWidth;
var cnavasHeight = window.innerHeight;
gameScreen.style.width = canvasWidth +"px";
gameScreen.style.height = cnavasHeight +"px";
basemap.width = canvasWidth;
basemap.height = cnavasHeight;
}
sizePage();
window.addEventListener("resize", function(){
sizePage();
})