Signature_pad: Canvas size responsive

Created on 9 Jul 2017  ·  3Comments  ·  Source: szimek/signature_pad

Hi,

I need to create a responsive signature pad with 100% width and specific height (300px)

How can i do this?

Most helpful comment

Afaik you can't set canvas width to a percentage, but you can place the canvas element in a container that has it's width set to 100%, then read the exact width of said parent element with jQuery. Then you can set the canvas width manually. Do this before you intialize SignaturePad.

var canvas = document.querySelector("canvas");
var parentWidth = $(canvas).parent().outerWidth();

canvas.setAttribute("width", parentWidth);

this.signaturePad = new SignaturePad(canvas);

All 3 comments

@50l3r was you able to do that ?
@szimek any suggestions please ? :) I see a PullRequest exist for that, and is old old :)
https://github.com/szimek/signature_pad/pull/100

Afaik you can't set canvas width to a percentage, but you can place the canvas element in a container that has it's width set to 100%, then read the exact width of said parent element with jQuery. Then you can set the canvas width manually. Do this before you intialize SignaturePad.

var canvas = document.querySelector("canvas");
var parentWidth = $(canvas).parent().outerWidth();

canvas.setAttribute("width", parentWidth);

this.signaturePad = new SignaturePad(canvas);

Sorry for delay.

It works :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hostcia picture hostcia  ·  6Comments

erangaapp picture erangaapp  ·  8Comments

Emmark picture Emmark  ·  4Comments

kevinchung1026 picture kevinchung1026  ·  5Comments

chitgoks picture chitgoks  ·  5Comments