我已经在这里设置了一个笔 http://codepen.io/prantikv/pen/GgNNwQ?editors=101
我正在使用mousedown方法,然后使用事件来画出线条,代码如下:
var signTouch=false;
var penWidth=2;
var el = document.getElementById('signPad');
var jqEl = jQuery('#signPad')
var ctx = el.getContext('2d');
ctx.lineWidth = penWidth;
ctx.canvas.width=window.innerWidth;
var isDrawing;
el.onmousedown = function(e) {
signTouch=true;
isDrawing = true;
ctx.lineWidth = penWidth;
ctx.lineJoin = ctx.lineCap = 'round';
ctx.moveTo(e.clientX - jqEl.position().left, e.clientY - jqEl.position().top);
};
el.onmousemove = function(e) {
if (isDrawing) {
console.log(e);
ctx.lineTo(e.clientX - jqEl.position().left, e.clientY - jqEl.position().top);
ctx.stroke();
}
};
el.onmouseup = function() {
isDrawing = false;
};
$(document).on('pageshow', '#index' ,function () {
$("#popupCloseRight").popup( "open" );
});
$("#nextchk").click(function(){
ctx.clearRect(0,0,el.width,el.height);
});
最后一个函数应该清除画布。它确实清除了,但之前绘制的线条会重新出现。
我没有使用任何数组来存储路径,但我对 e.clickX 的基本知识缺失一些,它是一个数组吗?
请给予建议。