直接上代码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
#can{
background: #ccc;
}
</style>
<script>
window.οnlοad=function(){
var can=document.getElementById("can")
var obj=can.getContext("2d")
can.οnmοusedοwn=function(e){
var ox=e.layerX
var oy=e.layerY
obj.moveTo(ox,oy)
can.οnmοusemοve=function(e){
var mx=e.layerX
var my=e.layerY
obj.lineTo(mx,my)
obj.stroke()
}
can.οnmοuseup=function(){
can.οnmοusemοve=null
}
}
}
</script>
</head>
<body>
<canvas id="can" width="1200" height="900"></canvas>
</body>
</html>