After a quick test, I'm not sure Chrome or Firefox will even make the canvas so big. My bet would be to create a canvas element, but never add it to the DOM. Similar:
var hiddenCanvas = document.createElement('canvas'); hiddenCanvas.width = 128000; hiddenCanvas.height = 128000; var hiddenContext = hiddenCanvas.getContext('2d');
Then create a smaller canvas that actually displays part of your hidden canvas
<canvas width="something reasonable" height="something reasonable" id="viewCanvas"/>
And use the drawImage method to draw the fragments:
var viewCanvas = document.getElementById('viewCanvas'); var viewContext = viewCanvas.getContext('2d'); viewCanvasContext.drawImage(hiddenCanvas, 40, 50, viewCanvas.width, viewCanvas.height, 0, 0, viewCanvas.width, viewCanvas.height);
Then you will have to either offer the up / down / right / left buttons to move, or maybe fake scrollbars using 20x wide DIVs that only show scrollbars and which you will type onverroll even listener on. And each time the user changes position, repeat the call to drawImage, updating the x / y positions (40 and 50 in my example).
Having said that, again, even when hidden, I doubt that browsers will work with a large canvas.
Iβm looking for a solution to the same problem, so if you are lucky in your research, share them.