How to draw a line using html5 canvas between a mousedown and mouseup of a button. Aslong as the button is clicked(mousedown), the line is drawn and stopped on mouseleave
<button id="drawLine" onmousedown="mouseDown()" onmouseup="mouseUp()">Draw
Line</button>
<canvas id="myCanvas" width="200" height="200" ></canvas>
var el=document.getElementById("drawLine");
var canvasEl=document.getElementById("myCanvas");
var line= canvasEl.getContext("2d");
var flag;
var count = 30;
line.beginPath();
line.moveTo(30,30)
function mouseDown(){
flag =true;
while(mdflag){
line.lineTo(count++,30);
line.stroke();
}
}
function mouseUp(){
flag = false;
}