View Full Version : Fullbrowser canvas element w/o scrollbars

07-14-2011, 02:59 AM
I'm playing around with full browser canvas element it seems to spill beyond the browser bounds generating horizontal and vertical scrollbars.

This is the technique I'm using:

<canvas id="c" width="1" height="1"></canvas>
<script type="text/javascript">
var ce = document.getElementById("c");
var cc = ce.getContext("2d");

function draw() {
var ctx = (cc);
ctx.canvas.width = window.innerWidth;
ctx.canvas.height = window.innerHeight;
ctx.fillStyle = "rgba(0, 0, 0, 0.5)";
ctx.fillRect(0, 0, ctx.canvas.width, 100);

$(window).resize($.debounce(100, function() {

I've also tried to wrap the canvas element inside a div and set that div's overflow equal to hidden, but the results are unchanged.

Does anyone have any insight on this?

07-14-2011, 04:40 AM
html, body {width:100%;height:100%;overflow:hidden;}
c {width:100%;height:100%;display:block;}

or you could use innerheight & innerwidth and resize on window resize to guarantee the window is always full...

07-14-2011, 04:53 AM
Yea, I originally had the overflow:hidden on the html & body elements but I wanted to see if there was another way.

I'll try out the innerwidth/innerheight and see how that goes.

Thank you for the reply, ereignis!