I'm trying to make the canvas with p5.js resize together with a div in which it is in when clicking on a button that extends this div giving it additional height. I don't need the canvas to reload, instead I just need it to add some additional height. Is there a way to do it? I tried making the canvas width 100% and height: auto, but it doesn't work. Please, see the code below:
<div class="canvas-wrapper">
<div id="canvas"></div>
</div>
<button type="button" class="button" id="extend-canvas">Extend</button>
Scripts:
function setup() {
var myCanvas = createCanvas(498, 598);
myCanvas.parent('canvas');
}
$( "#extend-canvas" ).click(function() {
var canvasHeight = $(".canvas-wrapper").height();
$(".canvas-wrapper").height(canvasHeight + 300);
});
CSS:
.canvas-wrapper {
margin: 0 auto;
background: #fff;
width: 500px;
height: 600px;
position: relative;
}
#canvas canvas {
width: 100% !important;
height: auto !important;
}