0
如何使點擊該圓圈開始畫一條直線,當你點擊第二個點止損拉線?就我而言,畫一條線會擦除整個畫布。對不起,我的英文不好在圓圈畫布上點擊鼠標並畫線?
var canvas = document.getElementById('circle');
var ctx = canvas.getContext('2d');
canvas.width = 800;
canvas.height = 600;
var rect = can.getBoundingClientRect();
function dots1() {
ctx.beginPath();
ctx.arc(50 , 80, 4, 0, 2*Math.PI, true);
ctx.fillStyle ="#" + Math.floor(Math.random()*0xFFFFFF).toString(16);
ctx.fill();
ctx.stroke();
};
function dots2() {
ctx.beginPath();
ctx.arc(120 , 220, 4, 0, 2*Math.PI, true);
ctx.fillStyle ="#" + Math.floor(Math.random()*0xFFFFFF).toString(16);
ctx.fill();
ctx.stroke();
};
canvas.onmousemove = function() {
c.clearRect(0,0,canvas.width,canvas.height);
c.strokeStyle = 'blue';
c.lineWidth = 1;
c.beginPath();
c.moveTo(letsdraw.x, letsdraw.y);
c.lineTo(event.clientX - rect.left, event.clientY - rect.top);
c.stroke();
};
canvas.onmousedown = function() {
letsdraw = {
x:event.clientX - rect.left,
y:event.clientY - rect.top
};
};
canvas.onmouseup = function() {
letsdraw = null;
};
哦,是的是的是我的謬論。 –