This time I will share jQuery Plugin and tutorial about Touch-enabled Signature Plugin with jQuery and Canvas, hope it will help you in programming stack.
Signature is a lightweight jQuery plugin that creates an Html5 canvas based signature pad for smooth, touch-enabled signature drawing.
How to use it:
1. Add the latest jQuery library and the jQuery signature plugin into the web page.
1 |
< script src = "//code.jquery.com/jquery-2.1.4.min.js" ></ script > |
2 |
< script src = "jq-signature.js" ></ script > |
2. Create a signature field as follow. You can pass the options to the signature field using Html5 data-option
attributes.
1 |
< div class = "js-signature" |
4 |
data-border = "1px solid #1ABC9C" |
5 |
data-background = "#16A085" |
3. Create buttons to clear and save your signature.
1 |
< button id = "clearBtn" onclick = "clearCanvas();" >Clear Canvas</ button > |
2 |
< button id = "saveBtn" onclick = "saveSignature();" disabled>Save Signature</ button > |
4. Create an empty element to place your saved signature for download.
5. The JavaScript to enable the signature field.
01 |
$(document).on( 'ready' , function () { |
02 |
$( '.js-signature' ).jqSignature(); |
05 |
function clearCanvas() { |
06 |
$( '#signature' ).html( '<p><em>Your signature will appear here when you click "Save Signature"</em></p>' ); |
07 |
$( '.js-signature' ).jqSignature( 'clearCanvas' ); |
08 |
$( '#saveBtn' ).attr( 'disabled' , true ); |
11 |
function saveSignature() { |
12 |
$( '#signature' ).empty(); |
13 |
var dataUrl = $( '.js-signature' ).jqSignature( 'getDataURL' ); |
14 |
var img = $( '<img>' ).attr( 'src' , dataUrl); |
15 |
$( '#signature' ).append($( '<p>' ).text( "Here's your signature:" )); |
16 |
$(' #signature').append(img); |
19 |
$('.js-signature ').on(' jq.signature.changed ', function() { |
20 |
$(' #saveBtn').attr('disabled', false); |
6. You can also pass the options during initialization.
01 |
$( '.js-signature' ).jqSignature({ |
10 |
border: '1px dashed #AAAAAA' , |
13 |
background: '#FFFFFF' , |
7. Methods.
2 |
$().jqSignature( 'clearCanvas' ); |
5 |
$().jqSignature( 'getDataURL' ); |
Change log:
2016-07-14
2016-07-12
2015-09-05
- Fixing clearCanvas bug in IE11/Edge
This awesome jQuery plugin is developed by bencentra. For more Advanced Usages, please check the demo page or visit the official website.