时间:2021-07-01 10:21:17 帮助过:84人阅读
let c = document.getElementById("canvas") let canvas = document.createElement("canvas") let availHeight = document.documentElement.clientHeight let off = availHeight - 400 canvas.height = '350' canvas.width = c.clientWidth c.appendChild(canvas) let dr = canvas.getContext('2d') dr.strokeStyle = 'blue' canvas.addEventListener('touchstart',(e)=>{ dr.beginPath() dr.moveTo(e.changedTouches["0"].pageX,e.changedTouches["0"].pageY-off) }) canvas.addEventListener('touchmove',(e)=>{ dr.lineTo(e.changedTouches[0].pageX, e.changedTouches[0].pageY-off) dr.stroke() }) canvas.addEventListener('touchend',(e)=>{ dr.closePath() })
生成图片
let img = document.querySelector('canvas').toDataURL()
如需发送给后端,可以让后端支持base64或者blob、buffer
相关推荐:
h5新特性的用法:监听App自带的返回键
如何实现移动端的城市定位以及城市区域代码adcode
以上就是canvas原生实现前端网页移动端签名的详细内容,更多请关注Gxl网其它相关文章!