Ok, so you can do what you want by attaching to the window resize event like so:
$(window).resize(callbackFunc);
Here are the changes that I made to get it working.
$(document).ready(function () {
initialize();
updateSize();
});
$(window).resize(updateSize);
function updateSize() {
var sigCanvas = document.getElementById("canvasSignature");
var xOffset = 100;
var yOffset = 100; // header height
sigCanvas.setAttribute('width', window.innerWidth - xOffset);
sigCanvas.setAttribute('height', window.innerHeight - yOffset);
}
The xOffset
and yOffset
can be customised to your needs, we need to subtract from the width and height of the window otherwise the canvas will go off the page. Also make sure you run it when the page loads so the size is adjusted to the correct size then.