<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
*{margin: 0%;padding:0px;}
html body{background-color: pink;height: 100%;overflow: hidden;}
body{background-color: pink;}
#canvas{margin: 0% auto;background-color: gray;
position: absolute;
left: 0%;
top: 0%;
right: 0%;
bottom: 0%;
margin: auto;
}
</style>
</head>
<body>
<canvas id="canvas" width="600" height="600">
</canvas>
</body>
<script>
window.onload=function(){
var canvas=document.querySelector("#canvas");
if(canvas.getContext){
var ctx=canvas.getContext("2d");
canvas.onmousedown=function(event){
var event=event||window.event;
if(canvas.setCapture){
canvas.setCapture();
}
ctx.beginPath();
ctx.moveTo(event.clientX-canvas.offsetLeft,event.clientY-canvas.offsetTop);
document.onmousemove=function(event){
event=event||window.event;
ctx.save();
ctx.strokeStyle="pink";
ctx.lineTo(event.clientX-canvas.offsetLeft,event.clientY-canvas.offsetTop);
ctx.stroke();
ctx.restore();
}
document.onmouseup=function(event){
document.onmousemove=document.onmouseup=null;
}
}
return false
}
}
</script>
</html>