我有我希望有人的一個問題是能夠幫助...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);
}
問題:
$("#saveCanvasStates").click(function() {
// save canvases and images on them to a database
});
在做一些拖放用戶需要能夠按下「保存」按鈕,在畫布之間滴加完畢(如圖所示JSFIDDLE ),這將將所有畫布的當前狀態保存到數據庫即:
- 保存所有的畫布到數據庫
- 保存一個圖像上畫布
這是爲了讓用戶可以再回來在稍後的時間,並從他們離開地方進行 - 拖放功能仍然有效。
這樣做最好的方法是什麼?因爲在這個特定主題上似乎只有很少的信息/材料,所以你對此的幫助將非常感謝,因爲任何JSFIDDLE示例都會有幫助 - 非常感謝
如果您將要求降低到:用戶可以回到他使用的相同瀏覽器並繼續離開,那麼您可以使用localStorage和FileAPI(尤其是localStorage),將會更容易。 – GameAlchemist