当前位置:网站首页>JS to realize the function of electronic signature
JS to realize the function of electronic signature
2022-07-18 03:18:00 【huaweichenai】
One :elesigncode Expansion package download
1:github Address :https://github.com/yinhui1129754/elesigncode
2:npm download :
npm install elesigncodeTwo :elesigncode Common methods
| Method name | describe | Parameters | Return value |
| init | Initialization method | nothing | nothing |
| undo | Revocation method | nothing | nothing |
| redo | Redo method | nothing | nothing |
| toJson | Convert the data signed by the current instance into json | nothing | nothing |
| toPng | Get the currently signed base64 Bit data png type | nothing | nothing |
| toJpeg | Get the currently signed base64 Bit data jpeg type | nothing | nothing |
| setColor | Set the color of the signature | color: Color string rgb hex All are OK | nothing |
| setLineWidth | Set the line width | lineWidth: Line width | nothing |
| setBgColor | Set the background color | bgColor: Color string rgb hex All are OK | nothing |
| setPen | Set the type of pen | name:'default' 'writing' | nothing |
| clear | Clear signature | nothing | nothing |
| isEmpty | Get whether it is signed | nothing | return true It means there is no signature , return false It means signing |
3、 ... and :elesigncode Implementation examples
1:html
<div id="test" style="width: 60%;height: 500px;margin: auto;border: 1px solid #333">
</div>
<button id="undo"> revoke </button>
<button id="clear"> eliminate </button>
<button id="getJson"> obtain json</button>
<button id="downloadPng"> Get transparent pictures </button>
<button id="downloadJpeg"> Get opaque pictures </button>2:js
<script type="text/javascript" src="./release/lib/dzjm.min.js"></script>
<script>
var ele = document.getElementById("test");
var eleSign = new EleSign({
ele: null
});// Instantiate objects
eleSign.init(); // initialization
eleSign.moutedEle(ele) // Put the signature node into the incoming element In nodes
eleSign.setPen("default");// Set the signature style :default( Default style ),writing( Brush style )
eleSign.setColor('#f00');// Set the signature color
eleSign.setBgColor('#333');// Set the background color
// Convert the data signed by the current instance into json
document.getElementById("getJson").addEventListener("click", function () {
var jsonStr = eleSign.toJson();
console.log(jsonStr);
alert(jsonStr);
})
// download png
document.getElementById("downloadPng").addEventListener("click", function () {
if (eleSign.isEmpty() === false) {
var baseUrl = eleSign.toPng();
var a = document.createElement("a");
document.body.appendChild(a);
a.setAttribute("href", baseUrl);
a.setAttribute("download", "png picture ");
a.click();
document.body.removeChild(a);
} else {
alert(' Please sign your name. ')
}
})
// download jpeg
document.getElementById("downloadJpeg").addEventListener("click", function () {
if (eleSign.isEmpty() === false) {
var baseUrl = eleSign.toJpeg();
var a = document.createElement("a");
document.body.appendChild(a);
a.setAttribute("href", baseUrl);
a.setAttribute("download", "jpeg picture ");
a.click();
document.body.removeChild(a);
} else {
alert(' Please sign your name. ')
}
})
// revoke
document.getElementById("undo").addEventListener("click", function () {
eleSign.undo();
})
// eliminate
document.getElementById("clear").addEventListener("click", function () {
eleSign.clear();
})
</script>As above, we can realize the function of electronic signature
边栏推荐
猜你喜欢

PD-Server GRPC 接口图解

Tencent Dajia Sharing | Tencent alloxio (DOP) in Financial scene Landing and optimization practice

ModuleNotFoundError: No module named ‘fake_ useragent‘

Tencent celebrities share | Tencent alluxio (DOP) landing and Optimization Practice in the financial scene

What is active metadata? Why Gartner predicts that it is a new direction of metadata management

Redis 过期的数据会被立马删除么?大有玄机

两个CVE漏洞复现

Data transmission: Practice of batch extraction of isomorphic and heterogeneous IP data sources

Configuration of teacher management module and MP automatic code generation

Play about the workplace: Senior HR tells you what characteristics strong people in the workplace have
随机推荐
ModuleNotFoundError: No module named ‘fake_useragent‘
家装工业软件的云挑战
Comparison of xssfworkbook, sxssfworkbook and easyexcel reading Excel files
从零实现深度学习框架——GloVe
“代码写的越急,程序跑的越慢”
[Xingguang 04] 2022 deep learning GPU form
Analyze the meaning of "collaboration" in collaborative office, and how can digital office easily "solve the problem"?
验证码与登录页面
Issue 100: encapsulate the flitter component of short answer
福昕软件亮相2022年全国化工企业数智化转型发展论坛
Listbox
线程-interrupt方法详解
js实现电子签名功能
Learning summary Note 6 (Gerui titant software - Jiuye practical training)
马斯克为何终止收购Twitter?
Issue 99: flutter learning (2)
ModuleNotFoundError: No module named ‘fake_ useragent‘
西山居如何用 ONES 打造游戏工业流水线?|ONES 行业实践
仓储系统亮灯分拣
Go zero micro service practical series (v. how to write cache code)