【发布时间】:2013-12-09 05:55:00
【问题描述】:
使用这个 JS Fiddle 我可以按一个按钮将新的画布添加到屏幕...
var next = 4
function addCanvas() {
// create a new canvas element
var newCanvas = document.createElement("canvas");
newCanvas.id = "addedcanvases" + next; //added this to give each new canvas a unique id
next++;
newCanvas.width = canvasWidth;
newCanvas.height = canvasHeight;
// add a context for the new canvas to the contexts[] array
contexts.push(newCanvas.getContext("2d"));
// link the new canvas to its context in the contexts[] array
newCanvas.contextIndex = contexts.length;
// wire up the click handler
newCanvas.onclick = function (e) {
handleClick(e, this.contextIndex);
};
// wire up the mousemove handler
newCanvas.onmousemove = function (e) {
handleMousemove(e, this.contextIndex);
};
// add the new canvas to the page
document.body.appendChild(newCanvas);
}
问题:
将静态图像分组/附加到画布顶部的最佳方法是什么(如下图所示),以便每当在 中创建新画布时JS Fiddle 使用它自动创建一个图像,该图像被分组/附加到新画布的顶部。
这样无论何时在页面上动态创建新画布时,都会在该画布上方放置图像?
我可能忽略了一种明显的方法来做到这一点?但是谷歌搜索并没有抛出太多,因为所有“图像”和“画布”搜索都不可避免地与实际向画布添加图像有关——这不是我在这种情况下想要做的。
【问题讨论】:
标签: javascript jquery html image canvas