Works out of the box…..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
<div id="signature-pad" class="m-signature-pad"> <div class="m-signature-pad--body"> <canvas></canvas> </div> </div> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/signature_pad/1.3.4/signature_pad.min.js"></script> <style type="text/css"> body { font-family: Helvetica, Sans-Serif; -moz-user-select: none; -webkit-user-select: none; -ms-user-select: none; } .m-signature-pad { position: relative; font-size: 10px; width: 400px; height: 400px; border: 1px solid #e8e8e8; background-color: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.27), 0 0 40px rgba(0, 0, 0, 0.08) inset; border-radius: 4px; } .m-signature-pad:before, .m-signature-pad:after { position: absolute; z-index: -1; content: ""; width: 40%; height: 10px; left: 20px; bottom: 10px; background: transparent; -webkit-transform: skew(-3deg) rotate(-3deg); -moz-transform: skew(-3deg) rotate(-3deg); -ms-transform: skew(-3deg) rotate(-3deg); -o-transform: skew(-3deg) rotate(-3deg); transform: skew(-3deg) rotate(-3deg); box-shadow: 0 8px 12px rgba(0, 0, 0, 0.4); } .m-signature-pad:after { left: auto; right: 20px; -webkit-transform: skew(3deg) rotate(3deg); -moz-transform: skew(3deg) rotate(3deg); -ms-transform: skew(3deg) rotate(3deg); -o-transform: skew(3deg) rotate(3deg); transform: skew(3deg) rotate(3deg); } .m-signature-pad--body { position: absolute; left: 20px; right: 20px; top: 20px; bottom: 20px; border: 1px solid #f4f4f4; } .m-signature-pad--body canvas { position: absolute; left: 0; top: 0; width: 100%; height: 100%; border-radius: 4px; box-shadow: 0 0 5px rgba(0, 0, 0, 0.02) inset; } @media screen and (max-width: 1024px) { .m-signature-pad { top: 0; left: 0; right: 0; bottom: 0; width: auto; height: auto; min-width: 250px; min-height: 250px; margin: 5%; } #github { display: none; } } @media screen and (min-device-width: 768px) and (max-device-width: 1024px) { .m-signature-pad { margin: 10%; } } @media screen and (max-height: 320px) { .m-signature-pad--body { left: 0; right: 0; top: 0; bottom: 32px; } .m-signature-pad--footer { left: 20px; right: 20px; bottom: 4px; height: 28px; } .m-signature-pad--footer .description { font-size: 1em; margin-top: 1em; } } </style> <button id="replace">Get data</button> <script type="text/javascript"> var w = document.getElementById("signature-pad"), c = w.querySelector("canvas"), b = document.getElementById("replace"); function resizeCanvas(canvas) { var ratio = window.devicePixelRatio || 1; canvas.width = canvas.offsetWidth * ratio; canvas.height = canvas.offsetHeight * ratio; canvas.getContext("2d").scale(ratio, ratio); } resizeCanvas(c); console.log("devicePixelRatio: " + window.devicePixelRatio); var data; var signaturePad = new SignaturePad(c); b.onclick = function () { data = signaturePad.toDataURL(); alert(data); signaturePad.clear(); setTimeout(function () { window.open(data); signaturePad.fromDataURL(data); }, 1000); }; </script> |