前言
html移动端手写自动横竖签名实现,并base64图片格式获取;
横竖根据屏幕宽高自动平铺。
效果图
图一
图二
实现
如下代码直接复制成.html文件打开即可预览效果
<!DOCTYPE html>
<html>
<head>
<title>手写签名</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<style>
html,body {
padding:0;
margin:0;
width: 100%;
height: 100%;
}
.text-center {
text-align: center;
}
#signature-button {
display: block;
margin: 0 auto;
border: 1px solid #6680ff;
background: #6680ff;
color: #fff;
border-radius: 4px;
padding: 8px 10px;
font-size: 16px;
cursor: pointer;
}
#signature-button:hover {
opacity: 0.8;
}
#signature-img {
width: 100%;
margin: 10px auto;
display: none;
}
#signature-pop {
position: fixed;
background-color: #fff;
top:0;
left:0;
bottom:0;
right:0;
width: 100%;
height: 100%;
display: none;
}
#signature-container {
width: 100%;
height: 100%;
}
.demo-top-info {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 40px;
background: #7b8bff;
box-sizing: border-box;
text-align: center;
color: #fff;
}
.demo-top-info .return {
padding-left: 5px;
height: 40px;
line-height: 40px;
position: absolute;
left: 10px;
display: inline-block;
cursor: pointer;
}
.signature-title {
height: 40px;
line-height: 40px;
display: inline-block;
}
.canvas-container {
width: 100%;
height: 100%;
background-color: #ffffff;
box-sizing: border-box;
padding: 40px 0 50px 0;
}
.canvas-parent {
width: 100%;
height: 100%;
}
.demo-bottom-info {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 50px;
background: #ffffff;
padding: 0 2%;
box-sizing: border-box;
overflow: hidden;
/* box-shadow: #efefef 0 -2px 5px 0; */
border-top: 1px solid #efefef;
}
#clean_canvas {
float: left;
font-size: 16px;
margin-top: 5px;
/* background: #f8f8f8; */
border: 1px solid #ddd;
padding: 8px 10px;
border-radius: 4px;
color: #323232;
cursor: pointer;
}
#sure_canvas {
float: right;
padding: 3px 0;
background: #7b8bff;
padding: 8px 10px;
border: 1px solid #7b8bff;
border-radius: 4px;
color: #fff;
margin-top: 5px;
cursor: pointer;
}
#clean_canvas:hover,
#sure_canvas:hover{
opacity: 0.8;
}
#canvas2 {
position: absolute;
top