Note that there are some explanatory texts on larger screens.

plurals
  1. POHTML5 Canvas - Saving and Restoring drag and drop canvas states
    text
    copied!<p>I have a problem I am hoping someone is able to help with...</p> <p>Using this <strong><a href="http://jsfiddle.net/perl_user/TBh4k/8/" rel="nofollow">JSFIDDLE</a></strong> I am able to dynamically create canvases and drag and drop images between all the different canvases.</p> <pre><code>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); } </code></pre> <p><strong>The problem:</strong></p> <pre><code>$("#saveCanvasStates").click(function () { // save canvases and images on them to a database }); </code></pre> <p>At the end of doing some dragging and dropping between the canvases the user needs to be able to press a 'Save' button (shown here <strong><a href="http://jsfiddle.net/perl_user/TBh4k/8/" rel="nofollow">JSFIDDLE</a></strong>) that will save the current state of all the canvases to a <strong>database</strong> i.e:</p> <ul> <li>save all the canvases to the database</li> <li>save which images are on which canvases</li> </ul> <p><strong>This is so that the user can then come back at a later time and carry on from where they left off</strong> - with the dragging and dropping feature still working.</p> <p>What would be the best way of going about doing this? because there appears to be very little information/material on this particular topic, so your help with this will be much appreciated as would any JSFIDDLE examples that would be helpful - thanks a lot</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload