首页 > 其他 > 详细

canvas实例--手写签名

时间:2020-08-19 15:23:16      阅读:81      评论:0      收藏:0      [点我收藏+]
技术分享图片
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
*{
margin:0;
padding:0;
}
body,html{
height:100%;
overflow: hidden;
background: #616161;
}
#test{
position: absolute;
left:50%;
top:50%;
transform: translate3d(-50%,-50%,0);
background: white;
margin:auto;
}
</style>
</head>
<body>
<canvas id="test">
<span>您的浏览器不支持canvas操作!!</span>
</canvas>
</body>
</html>
<script>
var canvas=document.querySelector(‘#test‘);
if(canvas.getContext){
var ctx=canvas.getContext("2d");}
canvas.onmousedown=function (ev) {
ev=ev||window.event;
if(canvas.setCapture){
canvas.setCapture();}
ctx.save(); //在栈里添加黑色
ctx.strokeStyle=‘pink‘; //将样式改成粉色
// ctx.lineWidth=10;
ctx.beginPath(); ctx.moveTo(ev.clientX-canvas.offsetLeft,ev.clientY-canvas.offsetLeft);
//鼠标移动时发生
document.onmousemove=function (ev) {
ev=ev||window.event;
ctx.lineTo(ev.clientX-canvas.offsetLeft,ev.clientY-canvas.offsetLeft);
ctx.stroke();
ctx.restore();};
document.onmouseup=function () {
document.onmousemove=document.onmouseup=null;
if(document.releaseCapture){
document.releaseCapture();}};
// ctx.restore();
return false;}
</script>

canvas实例--手写签名

原文:https://www.cnblogs.com/huaweimian/p/13529421.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!