Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested CANVAS elements

Tags:

html

Is it possible to have a element within another element? I know i can layer them, but is this possible -

<canvas id="parent">
    <canvas id="child"></canvas>
</canvas>

I tried but doesnt seem to work.

like image 317
Abhineet Avatar asked Jun 10 '11 13:06

Abhineet


1 Answers

If you want to handle background and foreground separately, you could use two canvas and put one above the other with css.

<canvas id="bg" width="640" height="480" style="position: absolute; z-index: 0">
</canvas>
<canvas id="fg" width="640" height="480" style="position: absolute; z-index: 1">
</canvas>

Actually this one of the tips to improve canvas performance. Source: HTML5 Rocks

like image 66
Isaac Zepeda Avatar answered Oct 17 '22 02:10

Isaac Zepeda