Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
44 lines (36 sloc) 930 Bytes
<!doctype html>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
<title>鼠标绘图</title>
<style type="text/css">
body{background: black}
#c1{background:white;}
span{color:white;}
</style>
</head>
<body>
<canvas id="c1" width="400" height="400">
<span>不支持canvas的浏览器就会显示</span>
</canvas>
<script type="text/javascript">
window.onload = function(){
var oc = document.getElementById('c1');
var content = oc.getContext('2d');
oc.onmousedown = function(e){
var e = e || window.event;
content.moveTo(e.clientX-oc.offsetLeft,e.clientY-oc.offsetTop);
document.onmousemove = function(e){
var e = e || window.event;
content.lineTo(e.clientX-oc.offsetLeft,e.clientY-oc.offsetTop);
content.stroke();
};
document.onmouseup = function(){
document.onmousemove = null;
document.onmouseup = null;
};
};
}
</script>
</body>
</html>
You can’t perform that action at this time.