javascript - Set the background in canvas using layer (zIndex) -



javascript - Set the background in canvas using layer (zIndex) -

i need background on canvas using layers. variable it's background. know should utilize css , set z-index, not know how in case.

js:

function dofirst(){ var x = document.getelementbyid('canvas'); canvas = x.getcontext('2d'); var item1 = new image(); item1.src = "images/sheep.png"; item1.addeventlistener("load", function() { canvas.drawimage(item1,20,300)}, false); var item2 = new image(); item2.src = "images/tshirt.png"; item2.addeventlistener("load", function() { canvas.drawimage(item2,300,300)}, false); var background = new image(); background.src = "images/background.png"; background.addeventlistener("load", function() { canvas.drawimage(background,0,0,1024,768)}, false); }

html:

<canvas id="canvas" width="1024" height="768">

the canvas element not designed address layers within element, you'll need approach problem using multiple canvas elements instead.

here's article assist approach

javascript canvas

Comments

Popular posts from this blog

javascript - mongodb won't find my schema method in nested container -

Hibernate criteria by a list of natural ids -

ios - Lagging ScrollView with UIWebview inside -