Comment: html5 simple drawing board code sharing, please refer to it
HTML5 simple drawing board
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<title></title>
<meta charset="UTF-8">
<script src="<a href="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script">"></script</a>>
</head>
<style>
canvas{ border:2px solid #000;}
</style>
<body>
<canvas></canvas>
<script type="text/javascript">
$(document).ready(function(){
var canvas=document.getElementById("draw");
var draw=canvas.getContext("2d");
draw.lineWidth=5;//Line thickness
draw.strokeStyle="red"; //Color
var godraw=false;
//Press the mouse
$("#draw").mousedown(function(e){
//Accurate coordinates
var mouseX=e.pageX-this.offsetLeft;
var mouseY=e.pageY-this.offsetTop;
draw.moveTo(mouseX,mouseY);
godraw=true;</p><p> })
//Let the mouse
$("#draw").mouseup(function(e){
godraw=false;
})
//Move the mouse
$("#draw").mousemove(function(e){
if(godraw){
var mouseX=e.pageX-this.offsetLeft;
var mouseY=e.pageY-this.offsetTop;
draw.lineTo(mouseX+4,mouseY+4);
draw.stroke();
}</p><p> })
})
</script>
</body>
</html>
Reproduction diagram