- Calling
resizeCanvas
clears the canvas, so you need to re-fill the canvas with the background color. - When you are resizing the canvases you need to check the actual
offsetWidth
andoffsetHeight
of the respective. - As written,
canvasDiv
is function scoped, so even if you fix #2 and usecanvasDiv.offset...
, each instance mode sketch is going to be resized to match the size of the last div created. This is a wonderful example of the absolute evil of thevar
keyword. If you declarecanvasDiv
with thelet
keyword then it will be block scoped inside the for loop so that for each instance thecanvasDiv
variable will reference the appropriate div.
To better illustrate point #3 here is a simplified example: