我遇到問題我希望有人能夠幫助。HTML5畫布 - 分組/將圖像附加到畫布上
使用這種JSFIDDLE我可以按一個按鈕來新畫布添加到屏幕...
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);
}
問題:
什麼是去的最佳途徑將靜態圖像分組/附加到畫布的頂部(如下圖所示),以便每當創建新畫布時,都會在JSFIDDLE圖像是自動創建的,它被分組/附加到新畫布的頂部。
這樣就可以在頁面上動態創建一個新的畫布,並將圖像放置在畫布上方?
有可能做到這一點,我俯瞰明顯的方式?但是使用谷歌搜索並沒有引起太大反響,因爲所有的「圖像」和「畫布」搜索都不可避免地涉及到實際添加圖像到畫布上 - 這不是我想要在這種情況下做的。
您對我們的幫助是非常讚賞,感謝
優秀 - 完美的作品,並感謝評論。在每次添加新的畫布時,使畫布出現在彼此之下而不是彼此相鄰,直到以前使用頁面寬度爲止?非常感謝 –
很高興我幫助了...如果你希望每個新組都位於前一組的右側,請查看CSS float:left指令:http://css-tricks.com/all-about-floats/ – markE
感謝您的鏈接 - 圖像成功添加與畫布現在感謝 - http://jsfiddle.net/perl_user/TBh4k/ –