These forums are currently read-only due to receiving more spam than actual discussion. Sorry.

It is currently Sat Dec 02, 2017 4:12 pm Advanced search

Canvas removal

If you are stuck or have questions regarding HTML or other Web technologies, ask your questions here. No question too dumb!

Canvas removal

Postby mindsclay » Sun Mar 18, 2012 4:01 pm

I can draw on, move, scale and all that with canvas. But no where can I see is the way to "close" the canvas or even erase it.

I have a book on HTML5 Canvas and I cannot find any reference to closing or erasing a canvas. It seems logical that that technology would exist.

Even searching on the web yielded nothing on this. Usually when I exhaust my resources the answer is "you can't do that". That would be really stupid if there is no way to close or erase a canvas instance.

So my question: How does one close or erase a canvas instance??? Can I at least make it transparent?
mindsclay
<h6>
 
Posts: 1
Joined: Sun Mar 18, 2012 3:51 pm

Re: Canvas removal

Postby JAB Creations » Sun Mar 18, 2012 11:29 pm

I don't work with Canvas at all however if I am correct Canvas has a root element? If so just use JavaScript's removeChild on the Canvas element.
User avatar
JAB Creations
<aside>
 
Posts: 566
Joined: Tue Mar 13, 2007 4:48 am
Location: Sarasota Florida, USA

Re: Canvas removal

Postby zcorpan » Mon Mar 19, 2012 7:24 am

If you want to clear the canvas, use clearRect
Code: Select all
context.clearRect(0, 0, canvas.width, canvas.height);

or set width or height on the canvas
Code: Select all
canvas.width = canvas.width;


If you want to remove a canvas, remove it from the document and drop all references to it.
Code: Select all
canvas.parentNode.removeChild(canvas);
canvas = context = null;
zcorpan
<article>
 
Posts: 807
Joined: Tue Feb 06, 2007 8:29 pm
Location: Sweden


Return to Help & Advice

Who is online

Users browsing this forum: No registered users and 1 guest