我有个问题 !在 html5 画布中,我创建了“x”个图像。最后创建的图像总是在另一个之上。是否可以在不需要库的情况下交换图像的深度?(我不打算颠倒变量的顺序)我想要这样的东西(没有动力学): http ://www.html5canvastutorials.com/kineticjs/html5-canvas-shape-layering-with-kineticjs/
所以,这是我正在使用的代码:
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
var imageObj = new Image();
imageObj.onload = function() {
context.drawImage(imageObj, 69, 50);
};
imageObj.src = "image1.png";
var imageObj2 = new Image();
imageObj2.onload = function() {
context.drawImage(imageObj2, 40, 30);
};
imageObj2.src = "image2.png";
/* I want to put "Image1.png" over "Image2.png" dynamically, for example, pressing a button, all this after render on the canvas */