canvas画线
2020-09-07 本文已影响0人
耍帅oldboy
<canvas id="c1" width="600" height="400"></canvas>
var c1=document.getElementById('c1');
var ctx=c1.getContext('2d');
c1.onmousedown = unciton(ev){
var _this = this;
var x = ev.pageX - this.offsetLeft;
var y = ev.pageY - this.offsetTop;
ctx.moveTo(x,y);
document.onmousemove = function(ev){
var x = ev.pageX - this.offsetLeft;
var y = ev.pageY - this.offsetTop;
ctx.lineTo(x,y);
ctx.stroke();
};
document.onmouseup = function(){
document.onmousemove = null;
document.onmouseup = null;
};
};