Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/415.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Signaturepad离开画布时停止书写_Javascript_Canvas_Touch_Signature - Fatal编程技术网

Javascript Signaturepad离开画布时停止书写

Javascript Signaturepad离开画布时停止书写,javascript,canvas,touch,signature,Javascript,Canvas,Touch,Signature,我需要一个能转换成图像的签名牌。 我开始使用VMAJSTER的代码。 我删除了羽毛并添加了图像创建选项 现在我遇到了一个问题,当你在写东西的时候(鼠标向下),离开你还在写的区域的时候,鼠标也在移动。如何在离开画布时添加书写停止 //源代码https://codepen.io/vmajster/pen/zYxowrv //作者:VMAJSTER (功能(){ /* 要做: 使用此脚本中的公式实现更自然的拖动运动: https://github.com/nashvail/SmootherTrell

我需要一个能转换成图像的签名牌。 我开始使用VMAJSTER的代码。 我删除了羽毛并添加了图像创建选项

现在我遇到了一个问题,当你在写东西的时候(鼠标向下),离开你还在写的区域的时候,鼠标也在移动。如何在离开画布时添加书写停止

//源代码https://codepen.io/vmajster/pen/zYxowrv
//作者:VMAJSTER
(功能(){
/*
要做:
使用此脚本中的公式实现更自然的拖动运动:
https://github.com/nashvail/SmootherTrello/blob/master/content.js
更多信息请访问:
https://uxdesign.cc/how-to-fix-dragging-animation-in-ui-with-simple-math-4bbc10deccf7
*/
var devicePixelRatio=window.devicePixelRatio | | 1;
var main=document.getElementById(“main”);
var canvas=document.getElementById(“绘制”);
var ctx=canvas.getContext(“2d”);
var sketch=document.getElementById(“sketch”);
var sketch_style=getComputedStyle(草图);
var inputType=“鼠标”;
canvas.width=parseInt(sketch_style.getPropertyValue(“width”),10);
canvas.height=parseInt(sketch_style.getPropertyValue(“height”),10);
//创建tmp画布
var tmp_canvas=document.createElement(“canvas”);
var tmp_ctx=tmp_canvas.getContext(“2d”);
tmp_canvas.id=“tmp_canvas”;
tmp_canvas.width=canvas.width;
tmp_canvas.height=canvas.height;
草图.附件(tmp_画布);
变量鼠标={
x:0,,
y:0
};
//笔尖
var-ppts=[];
/*捕鼠工作*/
tmp_canvas.addEventListener(“mousemove”,函数(e){
mouse.x=e.offsetX的类型!=“未定义”?e.offsetX:e.layerX;
mouse.y=e.offsetY的类型!=“未定义”?e.offsetY:e.layerY;
e、 停止传播();
e、 预防默认值();
返回false;
},假);
/*绘图*/
tmp_ctx.lineWidth=1.5*devicePixelRatio;/*绘制线的大小*devicePixelRatio*/
tmp_ctx.lineJoin=“round”;
tmp_ctx.lineCap=“圆形”;
tmp_ctx.strokeStyle=“rgba(0,0,0,0.8)”;
tmp_ctx.fillStyle=“rgba(0,0,0,0.8)”;
tmp_canvas.addEventListener(“鼠标向下”,函数(e){
tmp_canvas.addEventListener(“mousemove”,onPaint,false);
mouse.x=e.offsetX的类型!=“未定义”?e.offsetX:e.layerX;
mouse.y=e.offsetY的类型!=“未定义”?e.offsetY:e.layerY;
ppts.push({
x:mouse.x,
y:老鼠,y
});
onPaint(e);
},假);
tmp_canvas.addEventListener(“mouseup”,function()){
如果(输入类型==“触摸”){
}
否则{
inputType=“鼠标”;
}
tmp_canvas.removeEventListener(“mousemove”,onPaint,false);
//现在就开始写真正的画布
ctx.drawImage(tmp_画布,0,0);
//清除tmp画布
tmp_ctx.clearRect(0,0,tmp_canvas.width,tmp_canvas.height);
//清空笔尖
ppts=[];
},假);
var onPaint=函数(e){
//保存数组中的所有点
ppts.push({
x:mouse.x,
y:老鼠,y
});
如果(ppts.长度<3){
var b=PPT[0];
tmp_ctx.beginPath();
tmp_ctx.arc(b.x,b.y,tmp_ctx.lineWidth/2,0,Math.PI*2,0);
tmp_ctx.fill();
tmp_ctx.closePath();
e、 预防默认值();
e、 停止传播();
返回false;
}
//Tmp画布始终在绘制前清除。
tmp_ctx.clearRect(0,0,tmp_canvas.width,tmp_canvas.height);
tmp_ctx.beginPath();
tmp_ctx.moveTo(ppts[0].x,ppts[0].y);
对于(变量i=1;i