Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make canvas fill the whole page

How can I make canvas be 100% in width and height of the page?

like image 335
Sergei Basharov Avatar asked Sep 14 '10 08:09

Sergei Basharov


People also ask

How do I make my canvas 100% width?

In order to make the canvas full-screen width and height always, meaning even when the browser is resized, you need to run your draw loop within a function that resizes the canvas to the window. innerHeight and window.

How do you scale a canvas?

You can scale your canvas with content by "bouncing" the content off a temporary canvas while you resize the original canvas. This save+redraw process is necessary because canvas content is automatically cleared when you resize the canvas width or height.

How do you fill a canvas in HTML?

The fill() method in HTML canvas is used to fill the current drawing path. The default is black. The <canvas> element allows you to draw graphics on a web page using JavaScript. Every canvas has two elements that describes the height and width of the canvas i.e. height and width respectively.


1 Answers

Well I have it working here: Are Google's Bouncing Balls HTML5? by using the following CSS:

* { margin: 0; padding: 0;}  body, html { height:100%; }  #c {     position:absolute;     width:100%;     height:100%; } 

Where #c is the id of the canvas element.

like image 153
Ian Devlin Avatar answered Oct 05 '22 15:10

Ian Devlin