thread-pond / signature-pad

A jQuery plugin for assisting in the creation of an HTML5 canvas based signature pad. Records the drawn signature in JSON for later regeneration.
BSD 3-Clause "New" or "Revised" License
727 stars 292 forks source link

Canvas Clears when scrolling on iPad #156

Closed stevedurr closed 9 years ago

stevedurr commented 9 years ago

Hi

When I scroll a page on the iPad the drawn signature clears, the data stays but the drawing is removed.

If you then redraw it overlays it on to the first drawing.

Any ideas what I need to do to prevent it?

Steve

katalin2003 commented 9 years ago

Hello. The canvas clears itself when its dimensions or device orientation changes. Check that first.

On Tuesday, June 9, 2015, stevedurr notifications@github.com wrote:

Hi

When I scroll a page on the iPad the drawn signature clears, the data stays but the drawing is removed.

If you then redraw it overlays it on to the first drawing.

Any ideas what I need to do to prevent it?

Steve

— Reply to this email directly or view it on GitHub https://github.com/thomasjbradley/signature-pad/issues/156.

stevedurr commented 9 years ago

Yes I saw that or something similar on another issue.

The page has lots of content so when you scroll down on the iPad it clears the drawing (not the data).

thomasjbradley commented 9 years ago

That's really weird. The <canvas> element isn't being resized when the browser scrolls?

stevedurr commented 9 years ago

It is really weird. I'm going to do some investigating but I can't get the iPad to connect to Safari to inspect what is going on.

I'll let you know if I find out whats happening

stevedurr commented 9 years ago

I've found the error of my ways on this one. I'm using some javascript to make the canvas element responsive which resized the canvas, see below. I've highlighted the 3 lines added to fix my issue.

`//Get the canvas & context var c = $('#respondCanvas'); var ct = c.get(0).getContext('2d'); var container = $(c).parent();

//Run function when browser resize $(window).resize( respondCanvas );

function respondCanvas(){ c.attr('width', $(container).width() ); //max width c.attr('height', $(container).height() ); //max height var api = $('.sigPad').signaturePad(); var sig = api.getSignature(); api.regenerate(sig); } respondCanvas();`

$(document).ready(function() { $('.sigPad').signaturePad({ lineWidth: 0, drawOnly:true, errorClass: 'bg-danger', errorMessageDraw: 'Please sign the form' }); });

thomasjbradley commented 9 years ago

Okay; so you’ve got it working the way you want?

stevedurr commented 9 years ago

Yeah its all good. Nothing to do with your code, as I think we all probably expected...

Thanks

thomasjbradley commented 9 years ago

Glad to hear it!