Signature_Pad 采用原生JS编写,基于 HTML 5 画布。用 Bézier 曲线进行插补,使线条更平滑。它适用于所有现代桌面和移动浏览器,不依赖于任何外部库。
安装
bower 安装
bower install signature_pad
直接下载signature_pad.js 或者 signature_pad.min.js
signature_pad.js
signature_pad.min.js
使用API
var canvas = document.querySelector("canvas"); var signaturePad = new SignaturePad(canvas); // Returns signature image as data URL (see https://mdn.io/todataurl for the list of possible paramters) signaturePad.toDataURL(); // save image as PNG signaturePad.toDataURL("image/jpeg"); // save image as JPEG // Draws signature image from data URL signaturePad.fromDataURL("data:image/png;base64,iVBORw0K..."); // Clears the canvas signaturePad.clear(); // Returns true if canvas is empty, otherwise returns false signaturePad.isEmpty(); // Unbinds all event handlers signaturePad.off(); // Rebinds all event handlers signaturePad.on();