楼主看你的源码没看明白啊。自己写了一个简易版的,只为娱乐。希望以后大神写的插件能把注释加上啊。要不看起来挺吃力。谢谢。<canvas id="c1" width="400px" height="400px"> <!--宽高写在html里,写在css里有问题-->
<span> 该浏览器不支持canvas内容 </span> <!--对于不支持canvas的浏览器显示--> </canvas> <input type="button" value="按钮" id="submit" /> <input type="button" value="清除" id="clear" /> <img id="qmimg" /> </body> <script src="jquery-1.9.1.min.js"> </script> <script> var canvas = document.getElementById('c1'); var ctx = canvas.getContext('2d') canvas.addEventListener('touchstart', function(ev) { ev.preventDefault(); ctx.beginPath(); ctx.strokeStyle = 'red'; ctx.lineWidth = "5"; var ev = ev.touches[0] || window.event.touches[0]; ctx.moveTo(ev.clientX - canvas.offsetLeft, ev.clientY - canvas.offsetTop); canvas.addEventListener('touchmove', function(ev) { var ev = ev.touches[0] || window.event.touches[0]; ctx.lineTo(ev.clientX - canvas.offsetLeft, ev.clientY - canvas.offsetTop); ctx.stroke(); }) // canvas.addEventListener('touchend',function (ev) { // canvas.onmousemove = null; // canvas.onmouseup = null; // }) }) document.getElementById('clear').addEventListener("click", function() { canvas.width = canvas.width; }); document.getElementById('submit').addEventListener("click", function() { $('#qmimg').attr("src", canvas.toDataURL("image/png")); console.log('gasg') });回复
手机上不能用啊,不停的点击会有小红点出现,但是用手滑动并不能写字啊