Hey Everyone, I've been working on an HTML5 canvas project where I set the canvas width to $(window).width()
. Everything was going smoothly until I added a border, which caused a horizontal scroll to appear.
Important: I attempted to use the innerWidth()
function, but so far I haven't been able to solve the issue. My determination drives me to figure out why this problem is happening.
$(document).ready(function () {
$('canvas').width($(window).width());
$('canvas').height($(window).height());
console.log($(window).width())
})
* {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.home{
width:100%;
height:auto;
}
canvas{
display:block;
border:2px solid #0094ff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="home">
<canvas id="myCanvas"></canvas>
</div>