Question

I found this in a stackoverflow question on how to draw in canvas http://jsfiddle.net/ArtBIT/kneDX/ and now I want the canvas to cover my whole html page. For example:

<body>
  <div id="2">
    //code
  </div>
  <div id="2">
    //code
  </div>
</body>

So the canvas will be attached to the page and the user could draw over the content of the page. So is there any way to create the canvas inorder to take the 100% of the body be hidden apart from the drawing lines?

Edited:

How can I draw lines continuously without making circles in the above code? Also is there any way to draw something over the text without selecting it when you pass the mouse over it?

Was it helpful?

Solution

First, make the height and width properties of the canvas equal to the page height and page width. (Getting those values is quite difficult, so see the linked questions for the best way to do it -- or just use jQuery.)

Next, add some CSS to make the canvas sit in the absolute top-left corner of the page:

#canvas {
    position: absolute;
    top: 0;
    left: 0;
}

Then, don't change the background color of the canvas as you currently do by calling ctx.clearTo. Canvases are transparent by default, so you'll be able to see the page underneath of it, as long as you don't change the background color.

OTHER TIPS

Pass in the right width and height params instead of (200, 200)

Using window.screen.width and window.screen.height gives you this: http://jsfiddle.net/kneDX/878/

Update:

With this we will end up in canvas being as big as window and not the same size as client area. See apsillers's answer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top