2016-07-15 145 views
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; 

}; 

回答

0

看起来像一个简单的拼写错误 - 我想你的意思“环磷酰胺”而不是“C”在你的OnMouseMove功能

+0

哦,是的是的是我的谬论。 –