canvas简易画板
分类: 解决问题 6145 12
路径移动部分代码:
canvas.onmousedown = function(ev){
ev = ev || window.event;
_x = ev.clientX , _y = ev.clientY;
// 路径开始
cxt.beginPath();
cxt.moveTo(_x - canvas.offsetLeft , _y - canvas.offsetTop);
this.onmousemove = function(ev){
ev = ev || window.event;
x = ev.clientX , y = ev.clientY;
// 路径移动
cxt.lineTo(x - canvas.offsetLeft , y - canvas.offsetTop);
cxt.stroke();
}
// 路径结束
this.onmouseup = function(){
this.onmousemove = null;
}
}
clear.onclick = function(){
cxt.clearRect(0,0,canvas.width,canvas.height);
}
共 12 条评论关于 “canvas简易画板”